note 25850 added to function.count
| From: | richard at richard-sumilang dot com | Date: | Tue, 08 Oct 2002 22:38:48 +0000 |
| Subject: | note 25850 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37816@lists.php.net to get a copy of this message | ||
If you actually want to count the numbers in the following example...
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$result = count ($a);
// $result == 3
Then you can use this function I whipped up
function count_vals_in_array($array){
$n=0;
while(list($i) = each($array)){
$n=$n + $array[$i];
}
return $n;
}
count_vals_in_array($a);
//returns 9
--
http://www.php.net/manual/en/function.count.php
http://master.php.net/manage/user-notes.php?action=edit+25850
http://master.php.net/manage/user-notes.php?action=delete+25850
http://master.php.net/manage/user-notes.php?action=reject+25850