September 2001
Intermediate to advanced
768 pages
32h 45m
English
array array_count_values(array values) Counts the occurrences of all elements in the argument and returns an associative array of the resulting frequencies.
Returns:
Associative array; NULL if given an invalid argument
Description:
Passing an array to array_count_values() returns an associative array in which all the unique elements are counted and returned with the values as the keys and the frequencies as the values.
Version:
PHP 4 since 4.0b4
Example:
$scores = array('A', 'A', 'C', 'B', 'A', 'C', 'C', 'B', 'A');
$grades = array_count_values($scores);
echo "There were $grades[A] A's, $grades[B] B's, and $grades[C] C's";
Output: There were 4 A's, 2 B's, and ... |
Read now
Unlock full access