mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
optional param for count, thanks to Griggs Domler
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@135411 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
9103be9dd3
commit
d7609cabba
1 changed files with 38 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.count">
|
||||
<refnamediv>
|
||||
|
@ -11,7 +11,14 @@
|
|||
<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>
|
||||
<note>
|
||||
<simpara>
|
||||
The optional parameter <parameter>mode</parameter> is available as of
|
||||
PHP 4.2.0.
|
||||
</simpara>
|
||||
</note>
|
||||
<para>
|
||||
Returns the number of elements in <parameter>var</parameter>,
|
||||
which is typically an <type>array</type> (since anything else will have
|
||||
|
@ -22,6 +29,14 @@
|
|||
be returned (exception: <literal>count(&null;)</literal> equals
|
||||
<literal>0</literal>).
|
||||
</para>
|
||||
<para>
|
||||
The optinal parameter <parameter>mode</parameter> can be supplied to count
|
||||
recursive. To do so, set <parameter>mode</parameter> to
|
||||
<literal>1</literal>, or use the constant
|
||||
<constant>COUNT_RECURSIVE</constant>. The dafault value is
|
||||
<literal>0</literal>. For example, recursive count is usefull counting the
|
||||
elements of multidimensional arrays.
|
||||
</para>
|
||||
<warning>
|
||||
<para>
|
||||
<function>count</function> may return 0 for a variable that
|
||||
|
@ -53,6 +68,28 @@ $b[5] = 9;
|
|||
$b[10] = 11;
|
||||
$result = count ($b);
|
||||
// $result == 3;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>
|
||||
recursive <function>count</function> example (PHP >= 4.2.0)
|
||||
</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$food = $food = array( 'fruits' => array('orange', 'banana', 'apple'),
|
||||
'veggie' => array('carrot', 'collard','pea'));
|
||||
|
||||
// recursive count
|
||||
echo count($food,COUNT_RECURSIVE); // output 8
|
||||
|
||||
// normal count
|
||||
echo count($food); // output 2
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
Loading…
Reference in a new issue