Home  >  Article  >  Backend Development  >  PHP method to determine whether an array is one-dimensional or two-dimensional

PHP method to determine whether an array is one-dimensional or two-dimensional

小云云
小云云Original
2018-02-27 10:55:205357browse

How does PHP determine whether an array is one-dimensional or two-dimensional? Below we will use code to teach you how to determine.

1. First we have a PHP built-in function count();

count(array,mode); array是数组,mode默认为0,1是递归的计数
<?php   
if(count($arr) == count($arr,1)){  
     echo "是一维";  
}else{  
     echo "不是一维";  
}

Related recommendations:

php How to determine the dimension of an array Example code

Commonly used methods for PHP to determine whether an array is empty (five methods)

PHP determines whether the dimensions of an array Array are encapsulated functions

The above is the detailed content of PHP method to determine whether an array is one-dimensional or two-dimensional. 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