PHP Array count_values() Function
PHP array_count_values() Function
Last Updated : 17 Mar 2025
The array_count_values() function returns an array where the keys are the original array's values, and the values is the number of occurrences. In other words, we can say that array_count_values() function is used to calculate the frequency of all of the elements of an array.
Syntax
| Parameter | Description | Is compulsory |
|---|---|---|
| Array | Specifying the array. | compulsory |
Return Type
Returns an associative array, where the keys are the original array's values, and the values are the number of occurrences. This function is introduced in PHP 4
Example 1
Output:
Array( [3] => 2 [Hii] => 2 [World] => 1 )
Example 2
Output:
Array( [php] => 3 [T] => 2 [Point] => 1 )
Example 3
Output:
Array ( [Ajay]=>2 [Sid]=>2 [Rahul]=>1 [Ashish]=>1 )
Example 4
Output:
Array ( [Cricket] => 1 [Hockey] => 2 [Football] => 1 )
Next TopicPhp-array-current-function