Home  >  Article  >  Backend Development  >  PHP判断数组Array的维度(已封装函数)

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

WBOY
WBOYOriginal
2016-06-23 13:22:52974browse

有时候需要判断array的维度,上网查了下很多事类似 http://www.poluoluo.com/jzxy/201306/215088.html 这种写法,拉杂又搞不懂啥意思。下面是我写的:

    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;    }

版权声明:本文为博主原创文章,未经博主允许不得转载。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn