Home  >  Article  >  Backend Development  >  How to determine the dimensionality of an array in php

How to determine the dimensionality of an array in php

藏色散人
藏色散人Original
2021-03-10 10:26:252664browse

php method to determine the dimensionality of an array: first create a PHP sample file; then define a TestArray function; finally, traverse the foreach and "is_array" functions to determine the dimensionality of the array.

How to determine the dimensionality of an array in php

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

PHP checks whether the current array is a multi-dimensional array

/**
 * [TestArray 检测数组是一维还是二维]
 * @E-mial wuliqiang_aa@163.com
 * @TIME   2017-04-07
 * @WEB    http://blog.iinu.com.cn
 * @param [type] $array [数组]
 */
function TestArray($array){
    foreach($array as $v){
        if(is_array($v)){
            $Int_Array = array('status'=>2,'return'=>'检测为二维数组');
        }else{
            $Int_Array = array('status'=>1,'return'=>'检测为一维数组');
        }
    }
    return $Int_Array;
}

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to determine the dimensionality of an array in php. 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
Previous article:How to remove js in phpNext article:How to remove js in php