How to determine the dimensionality of an array in php

藏色散人
Release: 2023-03-08 15:26:02
Original
2673 people have browsed it

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;
}
Copy after login

[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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template