php count() function
Translation results:
UK[kaʊnt] US[kaʊnt]
n.Total number; count; charges; argument
v. Count; calculate the total; count...; important
Third person singular: counts Plural: counts Present participle: counting Past tense: counted Past participle: counted
php count() functionsyntax
Function:Return the number of elements in the array
Syntax:count(array,mode);
## Parameters:
Description | |
Required. Specifies an array. | |
Optional. Specify the mode. Possible values: 0 - default. Do not count all elements in a multidimensional array. 1 - Recursively count the number of elements in an array (count all elements in a multidimensional array). |
Description: For an array, return the number of its elements, for other values, return 1. If the argument is a variable and the variable is not defined, 0 is returned. If mode is set to COUNT_RECURSIVE (or 1), the number of array elements in a multidimensional array is recursively counted.
php count() functionexample
<?php $a = array("class" => "php中文网","name" => "西门","job" => "讲师"); print_r(count($a)); ?>
Run instance»
Click the "Run instance" button to view the online instance
Output:
3
<?php $cars=array ( "Volvo"=>array ( "XC60", "XC90" ), "BMW"=>array ( "X3", "X5" ), "Toyota"=>array ( "Highlander" ) ); echo "常规计数:" . count($cars)."<br>"; echo "递归计数:" . count($cars,1); ?>
Run Instance»
Click the "Run Instance" button to view the online instance
Output:
常规计数:3 递归计数:8