php查找某个值是否存在于多维数组中

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:29   1810   0
function deep_in_array($value, $array) {
        foreach($array as $item) {
            if(!is_array($item)) {
                if ($item == $value) {
                    return $item;
                } else {
                    continue;
                }
            }
 
            if(in_array($value, $item)) {
                return $item;
            } else if($this->deep_in_array($value, $item)) {
                return $item;
            }
        }
        return false;
 }

加入配置的值有多个子数组,改造下

  /**
     * @param $value
     * @param $array
     * @return bool
     * 某个值是否存在于多维数组中
     */
    public function deep_in_array($value, $array)
    {
        $total =[];
        foreach ($array as  $item) {
            if (!is_array($item)) {
                if ($item == $value) {
                    return $item;
                } else {
                    continue;
                }
            }
            if (in_array($value, $item)) {
                $total[] = $item;

            } else if ($this->deep_in_array($value, $item)) {
                $total[] = $item;
            }

        }
        return $total;

    }

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP