Searching Multidimensional Array for Value PHP
I feel like this is a pretty easy question, but I can't seem to find the answer anywhere.
$array = ('colors' => array('red','orange'),
'numbers'=> array('one','two')
);
How do a perform a search on the $array
to determine if colors
contai开发者_如何学Cns a value of red
?
Thanks in advance.
There is no built in array function to do this. Thes simplest way to to it in the specific case youve given is to do:
$hasRed = (isset($array['colors'] && in_array('red', $array['colors']));
Simplest way would be;
$hasRed = isset($array['colors']['red']);
Try this:
array_search("red", $array[ "colors" ])
精彩评论