php array_key_exists 的多维数组版本

由于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));

 

posted @ 2017-05-11 17:47  shijiu520  阅读(554)  评论(0)    收藏  举报