note 33528 added to function.count
| From: | ian at ianco dot co dot uk | Date: | Sun, 29 Jun 2003 10:46:31 +0000 |
| Subject: | note 33528 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51168@lists.php.net to get a copy of this message | ||
Counting arrays.
The webmaster post from Apr-2002 could give the impression that
count($array)
will give the number of dimensions in the array. This is not true, since after
$settings[0][0][0] = 128;
the following still holds:
echo count($settings) // returns 2
The following painful definition seems to work for me (so far!):
Let $var be a variable (which may be an array).
Let <S> be a sequence of zero or more of [key] .
( So $var<S> could be $var[0] , or $var['z'][3]['dolphins'] , or just $var
).
Then count($var<S>) will return
EITHER
if there are any, the number of set elements whose name is in the form
$var<S>[anotherkey]
ELSE
if $var<S> exists and is set, 1
ELSE
0
Maybe someone can express this better ;-)
----
Manual Page -- http://www.php.net/manual/en/function.count.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33528
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33528&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33528&report=yes