I am trying to search an array of arrays and if the needle is found I want to return or at least know the keys for the match.
For example given:
['foo'] =>
['bar'] => 'blah'
Searching for 'blah' I need to know there is a match and the keys are 'foo' and 'bar'
I have managed to implement a search which returns boolean for a match:
function search_array($needle, $haystack) {
if(in_array($needle, $haystack)) {
return true;
}
foreach($haystack as $element) {
var_dump($element);
if(is_array($element) && $this->search_array($needle, $element))
return true;
}
return false;
}
But I am struggling with how to know the keys. Is this even possible?