array_count_values
Count the number of values in the array
The array_count_values()
function counts all values in the array.
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 element's key name is the value of the original array, and the key value is the number of times the value appears in the original array.
Count all values in the array:
<?php $a = array ( "A" , "Cat" , "Dog" , "A" , "Dog" ) ; print_r ( array_count_values ( $a ) ) ; ?>
Try it yourself
array_count_values ( array )
parameter | describe |
---|---|
array | Required. Specifies an array that needs to count values. |