Home >Backend Development >PHP Tutorial >PHP implements a method to determine whether an array is one-dimensional, two-dimensional or several-dimensional
This article mainly introduces the method of PHP to determine whether an array is one-dimensional, two-dimensional or several-dimensional, involving PHP recursive operations and array-related determination skills. Friends in need can refer to the following
Examples of this article PHP implements a method to determine whether an array is one-dimensional, two-dimensional or several-dimensional. Share it with everyone for your reference, the details are as follows:
The custom function used here can determine whether the array is one-dimensional, two-dimensional, or several-dimensional:
function getmaxdim($vDim) { if(!is_array($vDim)) return 0; else { $max1 = 0; foreach($vDim as $item1) { $t1 = $this->getmaxdim($item1); if( $t1 > $max1) $max1 = $t1; } return $max1 + 1; } }
Verified and can be used:
//测试: $arr=array('yiyi'=>1212,'haha'=>array('heihei'=>array(array("a")),"b")); echo getmaxdim($arr); //结果: 4
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHP Two-dimensionalHow to sort an associative array according to one of the fields
The above is the detailed content of PHP implements a method to determine whether an array is one-dimensional, two-dimensional or several-dimensional. For more information, please follow other related articles on the PHP Chinese website!