A deep understanding of the count function of PHP array and a deep understanding of count. A deep understanding of the count function of PHP arrays, and a deep understanding of the countcount () PHPcount () function is used to calculate the number of cells in an array or the number of attributes in an object, returns the number of elements in the array or provides a deep understanding of the count function of the PHP array.
Count ()
The PHP count () function is used to calculate the number of units in an array or the number of attributes in an object, and returns the number of units in an array or the number of attributes in an object.
Syntax:
Int count (mixed var [, int mode]) If var is a non-array common variable, 1 is returned, and 0 is returned for nonexistent, uninitialized, or empty arrays.
The optional parameter mode is set to COUNT_RECURSIVE (or 1), and count () recursively counts the array, which is particularly useful for calculating all units of a multi-dimensional array, but count () it cannot recognize infinite recursion. The default value of mode is 0.
Example:
<? Phpecho count ($ x); // output: 0 $ a = 2; echo count ($ a); // output: 1 $ arr_age = array (18, 20, 25); echo count ($ arr_age); // output: 3?>
Sizeof () is the alias of this function.
In practice, some cyclic operations are often performed based on the size of the array. we recommend that you write count () in vitro:
<? Php $ arr_age = array (18, 20, 25); $ count = count ($ arr_age); for ($ I = 1; $ I <= $ count; $ I ++) {echo "Nth $ I cycle" ;}?>
In this way, you do not have to execute count () for each loop. of course, this is not necessary.
The above in-depth understanding of the count function of the PHP array is all the content shared by the editor. I hope to give you a reference and support for the help house.
The count function of the distinct array. the count () PHP count () function is used to calculate the number of units in the array or the number of attributes in the object, and return the number of units in the array or the number of objects...