From d7609cabba680c666a1c9108077150a5963b2515 Mon Sep 17 00:00:00 2001 From: Friedhelm Betz Date: Sat, 19 Jul 2003 06:51:26 +0000 Subject: [PATCH] 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 --- reference/array/functions/count.xml | 39 ++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/reference/array/functions/count.xml b/reference/array/functions/count.xml index 72ab32dcff..70d14b2fcf 100644 --- a/reference/array/functions/count.xml +++ b/reference/array/functions/count.xml @@ -1,5 +1,5 @@ - + @@ -11,7 +11,14 @@ intcount mixedvar + intmode + + + The optional parameter mode is available as of + PHP 4.2.0. + + Returns the number of elements in var, which is typically an array (since anything else will have @@ -22,6 +29,14 @@ be returned (exception: count(&null;) equals 0). + + The optinal parameter mode can be supplied to count + recursive. To do so, set mode to + 1, or use the constant + COUNT_RECURSIVE. The dafault value is + 0. For example, recursive count is usefull counting the + elements of multidimensional arrays. + count may return 0 for a variable that @@ -53,6 +68,28 @@ $b[5] = 9; $b[10] = 11; $result = count ($b); // $result == 3; +?> +]]> + + + + + + + recursive <function>count</function> example (PHP >= 4.2.0) + + + 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 + ?> ]]>