Home  >  Article  >  Backend Development  >  Example code for how to determine the dimensions of an array and whether the array is empty in PHP

Example code for how to determine the dimensions of an array and whether the array is empty in PHP

怪我咯
怪我咯Original
2017-07-10 13:40:531426browse

The following is a detailed analysis and introduction to the code for determining the dimensions of the php array. For reference, the code is as follows:

<?php 
/** 
 * 返回数组的维度 
 * @param  [type] $arr [description] 
 * @return [type]      [description] 
 */
function arrayLevel($arr){ 
    $al = array(0); 
    function aL($arr,&$al,$level=0){ 
        if(is_array($arr)){ 
            $level++; 
            $al[] = $level; 
            foreach($arr as $v){ 
                aL($v,$al,$level); 
            } 
        } 
    } 
    aL($arr,$al); 
    return max($al); 
} 

$arr = array( 
    &#39;0&#39;=>&#39;0&#39;, 
); 

echo arrayLevel($arr); 
?>

The following is the method to determine if the array is empty: empty($arr), the code is as follows

$arr= array(""); 
$result = empty($arr); 
//$result = false 
$arr = array(); 
$result = empty($arr); 
//$result = true

The above is the detailed content of Example code for how to determine the dimensions of an array and whether the array is empty in PHP. For more information, please follow other related articles on the PHP Chinese website!

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