php method to determine how many dimensions an array is: first obtain the array that needs to be determined; then use the custom "aL" method to determine how many dimensions the array is; finally use the "max($al)" method Just get the dimensions of the array.
##PHP Gets the number of dimensions of an array
Recommended: "PHP Tutorial"
// 判断数组是几维数组 $data = array(); // 是你要判断的数组 $al = array(0); function aL($data,&$al,$level=0){ if(is_array( $data )){ $level++; $al[] = $level; foreach($data as $v){ aL($v,$al,$level); } } } aL($data,$al); $num_level = max($al); // $num_level 就是你要获取的数组的维度
The above is the detailed content of PHP determines the number of dimensions of an array. For more information, please follow other related articles on the PHP Chinese website!