سؤال

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