当前位置:Gxlcms > PHP教程 > PHP判断数组Array的维度(已封装函数)_PHP教程

PHP判断数组Array的维度(已封装函数)_PHP教程

时间:2021-07-01 10:21:17 帮助过:32人阅读

PHP判断数组Array的维度(已封装函数)


有时候需要判断array的维度,上网查了下很多事类似种写法,拉杂又搞不懂啥意思。下面是我写的:

    private static function array_depth($array) {
        if(!is_array($array)) return 0;
        $max_depth = 1;
        foreach ($array as $value) {
            if (is_array($value)) {
                $depth = array_depth($value) + 1;

                if ($depth > $max_depth) {
                    $max_depth = $depth;
                }
            }
        }
        return $max_depth;
    }

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1073356.htmlTechArticlePHP判断数组Array的维度(已封装函数) 有时候需要判断array的维度,上网查了下很多事类似种写法,拉杂又搞不懂啥意思。下面是我写的: p...

人气教程排行