The array_count_values() is an inbuilt function in PHP which is used to count all the values inside an array. In other words we can say that array_count_values() function is used to calculate the frequency of all of the elements of an array.
array array_count_values( $array )
Parameters: This function accepts single parameter $array. This parameter is the array for which we need to calculate the count of values present in it.
Return Value: This function returns an associative array with key-value pairs in which keys are the elements of the array passed as parameter and values are the frequency of these elements in an array.
Note: If the element is not a string or integer then an E_WARNING is thrown.
Input : array = ("Geeks", "for", "Geeks", "Geeks", "Welcome", "for") Output : Array ( [Geeks] => 3 [for] => 2 [Welcome] => 1 ) Input : array = (1, 1, 2, 3 , 1 , 2 , 4, 5) Output : Array (  => 3  => 2  => 1  => 1  => 1 )
Below program illustrates the working of array_count_values() function in PHP:
Array ( [Geeks] => 3 [for] => 2 [Welcome] => 1 )
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.