php method to determine how many dimensions an array is: first create a PHP sample file; then define a foreachArray method; then use the "is_array" function to detect whether the variable is an array; finally determine whether the array is an array through loop traversal Just a few dimensions.
Recommended: "PHP Video Tutorial"
PHP Determines the Dimension of an Array
/** * 判断数组为几维数组 可优化 * @param array $array * @param int $count * @return int */ function foreachArray($array = [], $count = 1){ if (!is_array($array)){ return $count; } foreach ($array as $value){ $count++; if (!is_array($value)){ return $count; } return foreachArray($value, $count); } }
Related introduction:
is_array() function is used to detect whether a variable is an array.
Syntax
bool is_array ( mixed $var )
Parameter description:
$var: Variable to be detected.
Return value
If the detected variable is an array, TRUE is returned, otherwise FALSE is returned.
The above is the detailed content of How to determine the dimensions of an array in php. For more information, please follow other related articles on the PHP Chinese website!