Home > php教程 > PHP源码 > body text

确定数组维度

PHP中文网
Release: 2016-05-25 17:06:51
Original
984 people have browsed it

确定一个数组的维度

<?php
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;
 }
$array = array(array( array(array(1, 2), 3, 4)));
echo array_depth($array);
?>
 
输出:4
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template