Home > Article > Backend Development > PHP method to get the length of an array or the number of occurrences of a certain value, php array_PHP tutorial
The example in this article describes how PHP obtains the length of an array or the number of occurrences of a certain value. Share it with everyone for your reference. The specific analysis is as follows:
count(): Count the number of elements in the array;
For example:
$arr = Array('0','1','2','3','4'); echo count($arr); // 输出 5
sizeof() and count() have the same purpose. Both functions can return the number of array elements. You can get the number of elements in a regular scalar variable. 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 the number of times each specific value appears in the array $array;
For example:
$array=array(4,5,1,2,3,1,2,1); $ac=array_count_value($array);
will create an array named $ac, which includes:
Keyword Value
4 1
5 1
1 3
2 2
3 1
I hope this article will be helpful to everyone’s PHP programming design.