$a = [
'hill' => 'kill',
'krop' => [
'bar' => 'lego',
'foo' => 'mega'
]
];
function search($a)
{
foreach ($a as $key => $value) {
if ($key == 'foo') {
return TRUE;
}
return FALSE;
}
}
function search($needles, $haystack) {
$found = [];
array_walk_recursive($haystack, function($item, $key) use ($needles, &$found) {
if (in_array($key, $needles) && !in_array($key, $found))
$found[] = $key;
});
return (count(array_diff($needles, $found)) == 0);
}
print search(['foo', 'bar'], $a) ? 'true' : 'false';