You can use this function if you use a multi-dimensional array.
function array_key_exists_in_multi($key, $array)
{
$result = array_key_exists($key, $array);
foreach ($array as $value) {
$result = (is_array($value)) ? array_key_exists_in_multi($key, $value) : $result;
if ($result) return $result;
}
return $result;
}
This simple few lines function returns true if it finds any key from the array.
Example of the function:
if we pass this array as a parameter in the function, we can get the expected result.
$arr = array(
'1' => 100,
'2' => array(
'16' => 200,
'18' => array(
'example' => 100,
'101' => 101
),
),
'3' => 400
);
print array_key_exists_in_multi('example', $arr); //Output is: 1
print array_key_exists_in_multi('16', $arr); //Output is: 1
print array_key_exists_in_multi('2', $arr); //Output is: 1
print array_key_exists_in_multi('20', $arr); //Output is: 0