Home>Article>Backend Development> PHP determines the number of dimensions of an array

PHP determines the number of dimensions of an array

藏色散人
藏色散人 Original
2020-07-22 11:23:44 2853browse

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 determines the number of dimensions of an 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!

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