note 42765 deleted from function.count by tomsommer
| From: | tomsommer@php.net | Date: | Fri, 28 May 2004 20:36:01 +0000 |
| Subject: | note 42765 deleted from function.count by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70256@lists.php.net to get a copy of this message | ||
Note Submitter: php@kilrogg.net
----
When determining the size of a multi-dimensional array you can use this simple recursive function.
Note: This counts the arrays within an array itself as one element, so
<?php
$a = array(
1 => array("a", "b"),
2 => array("c")
);
?>
would result in a returned count of 5 !
<?php
function multicount($array)
{
$count = 0;
foreach($array as $key => $val)
{
$count++;
if (is_array($val))
$count += multicount($val);
}
return $count;
}
?>