The array_count_values () function is used to count the number of occurrences of all values in the array. This function returns an array with the key name of the element being the value of the original array, the key value is the number of times this value appears in the original array.
Array_count_values () definition and usage
The array_count_values () function is used to count the number of occurrences of all values in the array.
This function returns an array. The key name of the element is the value of the original array, and the key value is the number of times this value appears in the original array.
Syntax
Array_count_values (array) parameter description
Array is required. Specifies the input array.
Example
The code is as follows:
$ A = array ("Cat", "Dog", "Horse", "Dog ");
Print_r (array_count_values ($ ));
?>
Output:
Array ([Cat] => 1 [Dog] => 2 [Horse] => 1)