1
0
mirror of https://github.com/php/doc-de.git synced 2026-03-29 10:42:12 +02:00
Files
archived-doc-de/reference/array/functions/count.xml
Oliver Albers a25c3bb452 Sync to en, credits to tom
git-svn-id: https://svn.php.net/repository/phpdoc/de/trunk@198701 c90b9560-bf6c-de11-be94-00142212c4b1
2005-10-18 13:19:44 +00:00

140 lines
4.0 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<!-- EN-Revision: 1.17 Maintainer: simp Status: ready -->
<!-- CREDITS: tom -->
<refentry id="function.count">
<refnamediv>
<refname>count</refname>
<refpurpose>Zählt die Elemente einer Variable oder Attribute eines Objekts</refpurpose>
</refnamediv>
<refsect1>
<title>Beschreibung</title>
<methodsynopsis>
<type>int</type><methodname>count</methodname>
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>mode</parameter></methodparam>
</methodsynopsis>
<para>
Liefert die Anzahl von Elementen in <parameter>var</parameter>,
welches typischerweise ein <type>Array</type> ist, da alles andere
ein Element enthält.
</para>
<para>
Für Objekte, wenn die <link linkend="ref.spl">SPL</link> installiert
ist, gibt es die Möglichkeit das Interface Countable zu implementieren.
Dieses Interface besitzt die Methode <function>count</function>, die
den Rückgabewert für den Aufruf von <function>count</function> zurück
liefert.
</para>
<para>
Ist <parameter>var</parameter> kein Array oder Objekt mit Interface
Countable, wird <literal>1</literal> zurückgegeben (Ausnahme:
<literal>count(&null;)</literal> ist gleich <literal>0</literal>).
</para>
<note>
<simpara>
Anmerkung: Der Parameter mode wurde mit PHP 4.2.0 hinzugefügt.
</simpara>
</note>
<para>
Wenn der optionale Paramter <parameter>mode</parameter> auf
<constant>COUNT_RECURSIVE</constant> (oder 1) gesetzt ist, wird
<function>count</function> rekursiv die Anzahl der Elemente
ermittelt. Das ist besonders nützlich um alle Elemente eines
mehrdimensionalen Arrays zu ermitteln. Der voreingestellte Wert
von <parameter>mode</parameter> ist <literal>0</literal>.
<function>count</function> erkennt keine endlose Rekursion.
</para>
<caution>
<para>
<function>count</function> kann 0 zurückgeben wenn die Variable
nicht gesetzt ist, aber sie könnte ebenfalls 0 zurückgeben, wenn
eine Variable als leeres Array initialisiert wurde. Verwenden Sie
<function>isset</function> um zu testen, ob eine Variable gesetzt
ist.
</para>
</caution>
<para>
In der Sektion <link linkend="language.types.array">Arrays</link>
finden Sie eine detaillierte Erklärung, wie Arrays in PHP
implementiert sind und wie sie benutzt werden.
</para>
<para>
<example>
<title><function>count</function></title>
<programlisting role="php">
<![CDATA[
<?php
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$result = count($a);
//$result == 3
$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
$result = count($b);
// $result == 3
$result = count(null);
// $result == 0
$result = count(false);
// $result == 1
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>
Rekursives <function>count</function> Beispiel (PHP &gt;= 4.2.0)
</title>
<programlisting role="php">
<![CDATA[
<?php
$food = array('Obst' => array('Orange', 'Banane', 'Apfel'),
'Gemüse' => array('Karrotte', 'Kohl', 'Erbse'));
// rekursiv zählen
echo count($food, COUNT_RECURSIVE); // gibt 8 aus
// normales zählen
echo count($food); // gibt 2 aus
?>
]]>
</programlisting>
</example>
</para>
<para>
Siehe auch <function>is_array</function>,
<function>isset</function> und
<function>strlen</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->