PHP array_count_values() Function
Example
Count all values in the array:
<?php $a=array("A","Cat","Dog","A","Dog"); print_r(array_count_values($a)); ?>
Definition and Usage
The array_count_values() function counts all values in the array.
Description
The array_count_values() function is used to count the number of times all values appear in an array.
This function returns an array whose keys are the values of the original array, and whose values are the number of times the value appears in the original array.
Syntax
array_count_values(array)
Parameter | Description |
---|---|
array | Required. Specifies the array that needs to be counted for values. |
Technical Details
Return Value: | Returns an associative array whose keys are the values of the original array, and whose values are the number of times the value appears in the original array. |
PHP Version: | 4+ |