RE: [PHP] Counting elements in an array
| From: | Jay Blanchard | Date: | Wed, 19 Nov 2003 16:45:35 +0000 |
| Subject: | RE: [PHP] Counting elements in an array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-170314@lists.php.net to get a copy of this message | ||
[snip]
>> $fruit = array(orange,orange,apple,bananna,orange,apple,pear);
>>
>> How could I get the number of elements from $fruit where the value is
>> "orange"?
[/snip]
From http://www.php.net/array_keys with additions;
$array = array("blue", "red", "green", "blue",
"blue");
$countArray = count((array_keys($array, "blue")));
echo $countArray . "\n";
3