If mode is set to COUNT_RECURSIVE (or 1) in the count function, the number of elements in the array in the multi-dimensional array will be recursively calculated (that is, 12 in your result). If mode is not set, it defaults to 0. Multidimensional arrays (arrays within arrays) are not detected (result 3).
In this case, 3 will be output, because arrays in PHP do not require consecutive indexes. The reference manual has the following paragraph:
Array
An array in PHP is actually an ordered graph. A graph is a type that maps values to keys. This type is optimized in many ways, so you can use it as a real array, or a list (vector), a hash table (an implementation of a graph), a dictionary, a set, a stack, a queue and many more possibilities . It's also easy to simulate a tree since you can use another PHP array as a value.
Example
Obtain the length of the first dimension of a two-dimensional or multi-dimensional array. This is a common program judgment. For example, the array you read is a two-dimensional array:
If you want to count the length of the array $arr, that is to say, the two-dimensional array only has two news, the number you want is also 2, but if you use count($arr) different versions of PHP, the statistical result is Different;
Later, I found in the PHP manual that the count function has a second parameter, which is explained as follows:
The count function has two parameters:
0 (or COUNT_NORMAL) is the default, multi-dimensional arrays (arrays within arrays) are not detected;
1 (or COUNT_RECURSIVE) is to detect multi-dimensional arrays,
So if you want to determine whether the read array $arr contains news information, you need to write it like this:
Okay, at this point, the problem of obtaining the first dimension length of a two-dimensional or multi-dimensional array in PHP has been solved
http://www.bkjia.com/PHPjc/631599.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631599.htmlTechArticleFriends in need of the count multi-dimensional array length statistics implementation method in php can refer to it. The result of running the program below is (). The code is as follows. Copy the code ?$numb=array( array(10,15,30),ar...
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