note 84482 modified in function.count by danbrown
| From: | danbrown@php.net | Date: | Fri, 09 Jan 2009 22:58:32 +0000 |
| Subject: | note 84482 modified in function.count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149004@lists.php.net to get a copy of this message | ||
There doesn't seem to be a succinct method already noted on this page for counting
multidimensional array end nodes (Items in multidimensional arrays), so I thought this function
might help somebody.
Nice and simple :)
<?php
function rcount ($array) {
$count = 0;
if (is_array($array)) {
foreach($array as $id=>$sub) {
if (!is_array($sub)) { $count++; }
else { $count = ($count + rcount($sub)); }
}
return $count;
}
return FALSE;
}
?>
--was--
There doesn't seem to be a succinct method already noted on this page for counting
multidimensional array end nodes (Items in multidimensional arrays), so I thought this function
might help somebody.
Nice and simple :)
function rcount ($array) {
$count = 0;
if (is_array($array)) {
foreach($array as $id=>$sub) {
if (!is_array($sub)) { $count++; }
else { $count = ($count + rcount($sub)); }
}
return $count;
}
return FALSE;
}
http://php.net/manual/en/function.count.php