检查多维数组是否包含特定值

时间:2014-04-27 12:59:14

标签: php html arrays multidimensional-array

我有一个这样的数组:

array(
    [0] => array("description" => "old, white, brown_hair", "name" => "jacques"),
    [1] => array("description" => "young, black, black_hair", "name" => "jack")
);

现在我想检查数组是否包含jack。我试过了this

this is my code

1 个答案:

答案 0 :(得分:0)

您可以使用简单的foreach

foreach($arr as $k=>$arr1)
{
 if(in_array('jack',$arr1))
  {
    echo 'jack exists ! exiting....';
    break;
  }
}

Demo