You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
423 B
PHTML
20 lines
423 B
PHTML
5 years ago
|
<?php
|
||
|
function count_array_values($my_array, $match)
|
||
|
{
|
||
|
$count = 0;
|
||
|
|
||
|
foreach ($my_array as $key => $value)
|
||
|
{
|
||
|
if ($value == $match)
|
||
|
{
|
||
|
$count++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $count;
|
||
|
}
|
||
|
|
||
|
$colors = array("c1"=>"Red", "c2"=>"Green", "c3"=>"Yellow", "c4"=>"Red");
|
||
|
|
||
|
echo "\n"."Red color appears ".count_array_values($colors, "Red"). " time(s)."."\n";
|
||
|
?>
|