PHP determines the dimensions of an array Array (encapsulated function)
Sometimes I need to determine the dimensions of an array. I checked a lot of things on the Internet with similar writing methods, but I couldn’t figure out what they meant. Here’s what I wrote:
<code class="hljs" php=""> 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;
}</code>
http://www.bkjia.com/PHPjc/1073356.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1073356.htmlTechArticlePHP determines the dimensions of an array Array (encapsulated function) Sometimes it is necessary to determine the dimensions of an array, and I checked a lot on the Internet Things are written in similar ways, which makes me confused and I don’t understand what they mean. Here is what I wrote: p...
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