There is a function array_count_values() in PHP which counts the frequency of occurrences of all values of an array. The function returns an associative array with original values as keys and the number of occurrences as values.
Syntax: array_count_values(array)
Description of function parameters :
array: An array of values to count (Required)
Example:
<?php
$array = array(1, "test", 1, 'a', "test", 'a', 1, "hello");
echo "<pre>";
print_r(array_count_values($array));
echo "</pre>";
?>
Output:
Array
(
[1] => 3
[test] => 2
[a] => 2
[hello] => 1
)
0 Comment(s)