Home >Backend Development >PHP Tutorial >How to get the length of an array or the number of occurrences of a certain value in PHP_PHP Tutorial
This article mainly introduces the method of getting the length of an array or the number of occurrences of a certain value in PHP. The example analyzes count () and array_count_value(), friends in need can refer to it
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');
|
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;
1 2 |
$array=array(4,5,1,2,3,1,2,1); $ac=array_count_value($array); |
?
1 2 |
$array=array(4,5,1,2,3,1,2,1); $ac=array_count_value($array);
|