문제

I have the following array:

$var = array(
  key1 => array(value1, value2, value3),
  key2 => array(value4, value5, value6, value7)
);

How can I get the key of an array that contains, for example, value5?

도움이 되었습니까?

해결책

By using a simple foreach

foreach($var as $k=>$arr)
{
 if(in_array('value5',$arr))
 {
   echo $k;
   break;
 }
}

Demo

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top