码迷,mamicode.com
首页 > 编程语言 > 详细

php array_key_exists 的多维数组版本

时间:2017-05-11 18:39:19      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:bsp   function   turn   return   exists   版本   cti   style   code   

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

 

php array_key_exists 的多维数组版本

标签:bsp   function   turn   return   exists   版本   cti   style   code   

原文地址:http://www.cnblogs.com/shijiu520/p/6842009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!