在多维数组中搜索值 PHP [英] Searching Multidimensional Array for Value PHP
本文介绍了在多维数组中搜索值 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')
);
如何对 $array
执行搜索以确定 colors
是否包含 red
的值?
How do a perform a search on the $array
to determine if colors
contains a value of red
?
提前致谢.
推荐答案
没有内置的数组函数来做到这一点.在您给出的特定情况下,最简单的方法是:
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']));
这篇关于在多维数组中搜索值 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文