<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="快速确定php多维数组的深度的方法" id="card1">
<p> 游客</p><p>
标题:快速确定php多维数组的深度的方法<br/>
正文:<br/>
例如有一个多维数组： <br/>代码如下:<br/>array( <br/>array( <br/>array(1,3,4), <br/>array( <br/>array( <br/>1,2,3 <br/>) <br/>) <br/>), <br/>array( <br/>array(1,2), <br/>array(1) <br/>) <br/>) <br/><br/>这个数组的深度就是5，那么如何快速的确定一个数组深度。 @camnpr<br/><br/>其实，只是上面的答案应该再进行排序就可以了。下面清源分享一个简单的计算深度函数： <br/>代码如下:<br/>&amp;lt;?php <br/>function array_depth($array) { <br/>$max_depth = 1; <br/><br/><br/>foreach ($array as $value) { <br/>if (is_array($value)) { <br/>$depth = array_depth($value) + 1; <br/><br/><br/>if ($depth &amp;gt; $max_depth) { <br/>$max_depth = $depth; <br/>} <br/>} <br/>} <br/>return $max_depth; <br/>} <br/><br/>$array = array( array(&quot;11&quot;), array(),array( array(array(&quot;5&quot;, &quot;6&quot;), &quot;7&quot;, &quot;8&quot;)),array( array(array(&quot;5&quot;, &quot;6&quot;), &quot;7&quot;, &quot;8&quot;)), &quot;9&quot;, &quot;10&quot;); <br/>echo array_depth($array); <br/>?&amp;gt; <br/><br/>希望本文对广大php开发者有所帮助，感谢您阅读本文。<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=843&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=843&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=843&amp;Page=1">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=843">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=843">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>