由于array_key_exists不支持多维数组,只查到一维的,所以这个版本兼容
function multi_array_key_exists($needle,$haystack) { foreach ($haystack as $key => $value) { if ($needle == $key) return true; if (is_array($value)) { if (multi_array_key_exists($needle,$value) == true) return true; else continue; } } return false; } $arr = [ ‘first‘ => [ ‘a‘=>‘1‘, ‘b‘=>‘2‘ ], ‘two‘ => [ ‘c‘=>‘3‘, ‘d‘=>‘4‘ ], ]; var_dump(multi_array_key_exists(‘a‘,$arr));
时间: 2024-10-23 05:55:57