I've an associative array like this.
$lang['lbl_mylabel1'] = array('key1' => 'value1');
$lang['lbl_mylabel2'] = array('key2' => 'value1');
$lang['lbl_mylabel3'] = array('key3' => 'value1');
$lang['lbl_mylabel4'] = array('key4' => 'value2');
$lang['lbl_mylabel5'] = array('key5' => 'value3');
And I have a variable named value1
through which I want to compare values of the sub-array and return all those elements whose values are value1
.
So how can I use array_intersect
or any possible efficient method to return me the elements of $lang array
with values1.
The answer of above code should be the first 3 elements in the $lang array
.
The following code will preserve the structure of original $lang array:
Where $result will be: