$i = 0;
foreach ($fruit as $k)
 if ('prange' == $k)
   $i++;
(The result is $i, of course)

Jeff McKeon wrote:

How would I count the number of elements in an array that had a certain
value?

In other words, if I have

$fruit = array(orange,orange,apple,bananna,orange,apple,pear);

How could I get the number of elements from $fruit where the value is
"orange"?

Thanks,

Jeff




-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to