有时候需要判断array的维度,上网查了下很多事类似 http://www.poluoluo.com/jzxy/201306/215088.html 这种写法,拉杂又搞不懂啥意思。下面是我写的:
<code><span>private</span><span>static</span><span><span>function</span><span>array_depth</span><span>(<span>$array</span>)</span> {</span><span>if</span>(!is_array(<span>$array</span>)) <span>return</span><span>0</span>; <span>$max_depth</span> = <span>1</span>; <span>foreach</span> (<span>$array</span><span>as</span><span>$value</span>) { <span>if</span> (is_array(<span>$value</span>)) { <span>$depth</span> = array_depth(<span>$value</span>) + <span>1</span>; <span>if</span> (<span>$depth</span> > <span>$max_depth</span>) { <span>$max_depth</span> = <span>$depth</span>; } } } <span>return</span><span>$max_depth</span>; }</code>
以上就介绍了PHP判断数组Array的维度已封装函数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。