Question

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?

Was it helpful?

Solution

By using a simple foreach

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

Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top