Let's say I have an array like this:
Array
(
[id] => 1
[color_object] => blue
[color_1] => green
[color_2] => blue
[color_3] => blue
[color_4] => red
[color_5] => purple
[AltColor] => blue
)
I can use array_count_values and it will give me the count for blue as 4.
But I need to only count the values within specific keys of the array, in this example I need to limit my count to the color_1 color_2 color_3 color_4 and color_5 only.
Is it possible to only count the instances of blue within specified keys, giving me a desired result of 2?
PHP code:
$array = array("id"=>"1", "color_object"=>"blue", "color_1"=>"green", "color_2"=>"blue", "color_3"=>"blue", "color_4"=>"red", "color_5"=>"purple", "AltColor"=>"blue");
color_1,color_2, etc. elements? Why not make it an array'colors' => array('green', 'blue', 'blue', 'red', 'purple', 'blue')mysqli_fetch_assoc. I was trying to minimize the question, and I don't think I have as much control over the array as my question implied. Can you suggest a function reference to look into? I think maybe creating another array with just those keys might work in this instance.