note 42765 added to function.count
| From: | php at kilrogg dot net | Date: | Fri, 28 May 2004 12:34:53 +0000 |
| Subject: | note 42765 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70237@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.count.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42765
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42765&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42765&report=yes
Search -- http://master.php.net/manage/user-notes.php