In PHP, you can use the count() function to query how many elements an array has. The return result of this function is the number of array elements, and the syntax is "count(array, mode)"; the second parameter defaults to 0, which means that the elements in the multi-dimensional array are not counted. If set to 1, the multi-dimensional array elements are calculated recursively. .
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
Can I query how many elements there are in an array.
count() function returns the number of elements in the array.
Syntax
count(array,mode);
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 - Recursively count the number of elements in an array (count all elements in a multidimensional array).
Return value: Returns the number of elements in the array.
The example is as follows:
<?php $cars=array("Volvo","BMW","Toyota"); echo count($cars); ?>
The output result is 3.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Is it possible to query how many elements an array has in php?. For more information, please follow other related articles on the PHP Chinese website!