mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Fixed typo in last commit (count not coun). Added further examples. Used docbook markup appropriately.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@171989 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
3389d1408e
commit
5fad7fe088
1 changed files with 28 additions and 20 deletions
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.13 $ -->
|
||||
<!-- $Revision: 1.14 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.count">
|
||||
<refnamediv>
|
||||
<refname>count</refname>
|
||||
<refpurpose>Count elements in a variable</refpurpose>
|
||||
<refpurpose>Count elements in an array or an object</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
@ -15,20 +15,23 @@
|
|||
</methodsynopsis>
|
||||
<para>
|
||||
Returns the number of elements in <parameter>var</parameter>,
|
||||
which is typically an <type>array</type> (since anything other than objects
|
||||
will have one element).
|
||||
which is typically an <type>array</type>, since anything other than objects
|
||||
will have one element.
|
||||
</para>
|
||||
<para>
|
||||
For objects it returns the number of non static properties not taking
|
||||
visibility into account. If you have SPL starting from PHP 5.1 you can
|
||||
hook into coun() by implementing interface Countable. That interface
|
||||
has exactly one method named count() which delivers the return value
|
||||
for the count() function.
|
||||
For objects <function>count</function> will return the number of non static
|
||||
properties, not taking visibility into account. If you have
|
||||
<link linkend="ref.spl">SPL</link> installed, you can hook into
|
||||
<function>count</function> by implementing interface
|
||||
<literal>Countable</literal>. The interface has exactly one method,
|
||||
<function>count</function>, which returns the return value for the
|
||||
<function>count</function> function.
|
||||
</para>
|
||||
<para>
|
||||
If <parameter>var</parameter> is not an array, <literal>1</literal> will
|
||||
be returned (exception: <literal>count(&null;)</literal> equals
|
||||
<literal>0</literal>).
|
||||
If <parameter>var</parameter> is not an array or an object,
|
||||
<literal>1</literal> will be returned.
|
||||
There is one exception, if <parameter>var</parameter> is &null;,
|
||||
<literal>0</literal> will be returned.
|
||||
</para>
|
||||
<note>
|
||||
<simpara>
|
||||
|
@ -53,7 +56,7 @@
|
|||
</para>
|
||||
</caution>
|
||||
<para>
|
||||
Please see the <link linkend="language.types.array">Arrays</link>
|
||||
Please see the <link linkend="language.types.array">Array</link>
|
||||
section of the manual for a detailed explanation of how arrays
|
||||
are implemented and used in PHP.
|
||||
</para>
|
||||
|
@ -61,7 +64,6 @@
|
|||
<example>
|
||||
<title><function>count</function> example</title>
|
||||
<programlisting role="php">
|
||||
<!-- TODO: examples about count(null), count(false), count(object).. -->
|
||||
<![CDATA[
|
||||
<?php
|
||||
$a[0] = 1;
|
||||
|
@ -75,6 +77,18 @@ $b[5] = 9;
|
|||
$b[10] = 11;
|
||||
$result = count($b);
|
||||
// $result == 3;
|
||||
|
||||
$result = count(null);
|
||||
// $result == 0;
|
||||
|
||||
$result = count(false);
|
||||
// $result == 1;
|
||||
|
||||
$obj = new StdClass;
|
||||
$obj->foo = 'A property';
|
||||
$obj->bar = 'Another property';
|
||||
$result = count($obj);
|
||||
// $result == 2;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -102,12 +116,6 @@ echo count($food); // output 2
|
|||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
The <function>sizeof</function> function is an
|
||||
<link linkend="aliases">alias</link> for <function>count</function>.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
See also <function>is_array</function>,
|
||||
<function>isset</function>, and
|
||||
|
|
Loading…
Reference in a new issue