How to implement count multi-dimensional array length statistics in PHP. Friends in need can refer to it.
The result of running the following program is ()
The code is as follows | Copy code | ||||
array(10,15,30),array(10,15,30),array(10,15,30) );echo count($numb,1);
|
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).
代码如下 | 复制代码 |
$fruits = array ( echo(count($fruits[0])); |
代码如下 | 复制代码 |
$fruits[0][0]=1; echo(count($fruits[0])); |
The result is 3+9=12
Reference
The code is as follows | Copy code | ||||||||||||||||||||||||
$fruits = array (
Array (1, 2,null,null, 5, 6),
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;
{ ..... } else { ..... } ?>
Related labels:
source:php.cn
Previous article:Tag cloud implementation code generated by PHP and MySQL_PHP tutorial
Next article:Introduction to the use of recursive function return values in PHP (ecshop unlimited classification)_PHP tutorial
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
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|