PHP determines the dimensions of the array Array and has encapsulated functions

WBOY
Release: 2016-07-29 09:11:52
Original
1078 people have browsed it

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>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

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.

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!