PHP » Arrays » array_count_values()

Syntax:
array array_count_values(array array)
array
Array to be counted.

Returns the number of occurrences for each value in an array.

This function counts the number of occurrences of each element value in an array. The result is returned in the form of an array with the element values as keys, and the number of occurrences as values.

Examples

Code:
<pre>
<?php

$array1 = array(
   "Paris" => "France",
   "Rome" => "Italy",
   "New York" => "USA",
   "Los Angeles" => "USA");

$array1 = array_count_values($array1);
print_r($array1);

?>
</pre>
Output:
Array
(
   [France] => 1
   [Italy] => 1
   [USA] => 2
)
Explanation:

This example shows how array_count_values() works.

See Also: