Sometimes I need to judge the dimensions of the array. I checked online and found many things similar to http://www.poluoluo.com/jzxy/201306/215088.html. This way of writing is confusing and I don’t understand what it means. Here's what I wrote:
<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>
The above introduces the encapsulated function of judging the dimension of array Array in PHP, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.