This is where a recursive function comes in handy.
function multi_array_key_exists($key, array $array): bool
{
if (array_key_exists($key, $array)) {
return true;
} else {
foreach ($array as $nested) {
if (is_array($nested) && multi_array_key_exists($key, $nested))
return true;
}
}
return false;
}
Note that this can take some time (in long nested arrays), it might be better to flatten first, since you are only interested in whether the key exists or not.