note 29159 added to function.count
| From: | rodrigo at NOSPAM dot dhweb dot com dot br | Date: | Tue, 04 Feb 2003 18:04:22 +0000 |
| Subject: | note 29159 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43405@lists.php.net to get a copy of this message | ||
This is a function to count the arrays in a multimensional array.
// ->
$counter = 0;
function count_subarrays(&$val, &$key, &$counter) {
if (is_array($val)) {
$counter++;
array_walk (&$val, 'count_subarrays', &$counter);
}
}
array_walk ($array, 'count_subarrays', &$counter);
echo ($counter);
// <-
If you want to count all elements just move the "$counter++;" outside the if.
--
http://www.php.net/manual/en/function.count.php
http://master.php.net/manage/user-notes.php?action=edit+29159
http://master.php.net/manage/user-notes.php?action=delete+29159
http://master.php.net/manage/user-notes.php?action=reject+29159