mirror of
https://github.com/php/doc-de.git
synced 2026-03-25 15:52:10 +01:00
fixed svn properties git-svn-id: https://svn.php.net/repository/phpdoc/de/trunk@283886 c90b9560-bf6c-de11-be94-00142212c4b1
199 lines
5.1 KiB
XML
199 lines
5.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: n/a Maintainer: jumpa Status: ready -->
|
|
<!-- CREDITS: tom -->
|
|
<refentry xml:id="function.count" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>count</refname>
|
|
<refpurpose>Zählt alle Elemente eines Arrays oder Attribute eines Objekts</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<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>
|
|
Zählt alle Elemente eines Arrays oder Attribute eines Objekts.
|
|
</para>
|
|
<para>
|
|
Wenn Sie die <link linkend="ref.spl">SPL</link> installiert haben,
|
|
können Sie in Objekten eine <function>count</function>-Funktion
|
|
nutzen, indem Sie das Interface <literal>Countable</literal>
|
|
implementieren. Das Interface hat exakt eine Methode, nämlich
|
|
<function>count</function>, die den Rückgabewert der Funktion
|
|
<function>count</function> zurückliefert.
|
|
</para>
|
|
<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>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>var</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Das Array.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>mode</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Wenn der optionale Parameter <parameter>mode</parameter> auf
|
|
<constant>COUNT_RECURSIVE</constant> (oder 1) gesetzt ist, wird
|
|
<function>count</function> rekursiv durch das Array zählen.
|
|
Dies kann besonders nützlich sein, um alle Elemente eines
|
|
mehrdimensionalen Arrays zu zählen. Der Standardwert für
|
|
<parameter>mode</parameter> ist <literal>0</literal>.
|
|
<function>count</function> erkennt keine endlose Rekursion.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<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>
|
|
Ist <parameter>var</parameter> kein Array oder Objekt mit Interface
|
|
<literal>Countable</literal>, wird <literal>1</literal> zurückgegeben.
|
|
Es besteht eine Ausnahme, wenn <parameter>var</parameter> &null; ist,
|
|
in diesem Fall wird <literal>0</literal> zurückgegeben.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
<function>count</function> gibt 0 zurück, wenn die Variable nicht
|
|
gesetzt ist, aber sie gibt ebenfalls 0 zurück, wenn die Variable als
|
|
leeres Array initialisiert wurde. Verwenden Sie <function>isset</function>
|
|
um zu testen, ob eine Variable gesetzt ist.
|
|
</para>
|
|
</caution>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>4.2.0</entry>
|
|
<entry>
|
|
Der optionale Parameter <parameter>mode</parameter> wurde hinzugefügt.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>count</function>-Beispiel</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</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$food = array('Obst' => array('Orange', 'Banane', 'Apfel'),
|
|
'Gemüse' => array('Karotte', '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>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>is_array</function></member>
|
|
<member><function>isset</function></member>
|
|
<member><function>strlen</function></member>
|
|
</simplelist>
|
|
</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
|
|
-->
|