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 is used to count the number of occurrences of all values in an array.
array_count_values( array )
| parameter | describe |
|---|---|
| array | Required. Specifies an array that needs to count the occurrences of all values in the array. |
| Return value: | Returns an associative array, the key name of its element is the value of the original array, and the key value is the number of times the value appears in the original array. |
|---|---|
| PHP version: | 4+ |