Usage of count function in php: [count(array, mode)], where the parameter array specifies the array to be counted, and mode specifies the mode of the function. The count function is used to return the number of elements in an array.
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
count() function returns the number of elements in the array.
Syntax
count(array,mode);
Parameters:
array Required. Specifies the array to count.
#mode Optional. Specifies the mode of the function. Possible values: 0 - default. Not counting all elements in a multidimensional array. 1 - Count the number of elements in an array recursively (count all elements in a multidimensional array).
Example:
<?php $cars=array ( "Volvo"=>array ( "XC60", "XC90" ), "BMW"=>array ( "X3", "X5" ), "Toyota"=>array ( "Highlander" ) ); echo "Normal count: " . count($cars)."<br>"; echo "Recursive count: " . count($cars,1); ?>
Related recommendations:php tutorial
The above is the detailed content of How to use the count function in php. For more information, please follow other related articles on the PHP Chinese website!