In-depth understanding of the count function of the PHP array, in-depth understanding of count
Count ()
The PHP count () function calculates the number of cells in an array or the number of properties in an object, returns the number of cells in an array, or the number of properties in an object.
Grammar:
int count (mixed var [, int mode]) if VAR is a non-array normal variable, returns 1 for non-existent, uninitialized, or empty array 0.
The optional parameter mode is set to Count_recursive (or 1), and count () counts the array recursively, which is especially useful for all cells that calculate a multidimensional array, but count () does not recognize infinite recursion. The default value for mode is 0.
Example:
<?phpecho count ($x); Output: 0$a = 2;echo count ($a); Output: 1$arr_age = Array (+, +); Echo count ($arr _age); Output:3?>
sizeof () is the alias of this function.
In practice, some loops are often performed based on the size of the array, and it is recommended that count () be written outside the loop body:
<?php$arr_age = Array (+), $count = count ($arr _age), for ($i =1; $i <= $count; $i + +) { echo "$i cycles";}? >
This does not have to perform the count () calculation every time the loop is performed, which of course is not required.
This in-depth understanding of the PHP array count function is a small part of the whole content to share to everyone, I hope to give you a reference, but also hope that we have a lot of support to help guests home.
http://www.bkjia.com/PHPjc/1136647.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136647.html techarticle In- depth understanding of the count function of the PHP array, in-depth understanding count count () the PHP count () function is used to count the number of cells in an array or the number of properties in an object, return the number of cells in an array, or pair ...