Count the occurrences of all values in an array:
<?php $a=array(“A”,“Cat”,“Dog”,“A”,“Dog”); print_r(array_count_values($a)); ?> |
The array_count_values()
function counts the frequency of each value in an array.
array_count_values(array) |
Parameter |
Description |
array |
Required. Specifies the array for which to count the values. |
Return Value: |
Returns an associative array where the keys are the original array’s values and the values are their respective counts. |
PHP Version: |
4+ |