Home > Article > Backend Development > PHP counts the number of array elements, the number of PHP arrays_PHP tutorial
count(): counts the number of elements in the array;
sizeof(): It has the same purpose as count(). 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 an array that has not been passed For the set variable, the number of array elements returned is 0;
array_count_value(): counts the number of times each specific value appears in the array $array;
such as:
$array=array(4,5,1,2,3,1,2,1);
$ac=array_count_value($array);
will create a Named $ac array, the array includes:
4 1
5 5 1
1 3
2 2
3 1
Article source address: http://www .cnblogs.com/taletao/archive/2012/04/26/2471338. html
www.bkjia.com