Home > Article > Backend Development > PHP counts the number of array elements
count(): counts the number of elements in the array;
sizeof(): has the same purpose as count(). Both functions can return the number of array elements. You can get the elements in a regular scalar variable Number, if the array passed to this function is an empty array, or a variable that has not been set, the number of array elements returned is 0;
array_count_value(): counts each specific value in the array $array The number of occurrences;
For example:
$array=array(4,5,1,2,3,1,2,1);
$ac=array_count_value($array);
will create an array named $ac , the array includes:
3 2471338.html
The above introduces PHP to count the number of array elements, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.