Home  >  Article  >  Backend Development  >  PHP counts the number of array elements

PHP counts the number of array elements

WBOY
WBOYOriginal
2016-08-08 09:21:44838browse

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.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn