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( '0'=>'0', ); 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!