Wednesday, 3 January 2018

PHP program to calculate frequency | array_count_values() function

Tags

array_count_values function is an inbuilt function of PHP. This function is use to calculate the frequency of the elements of array. This function takes a single parameter i.e an array. This function returns an associative array with key value pairs, where key are the elements of array and value is their respective frequency in the array.

array_count_values($array)

PHP program to calculate the frequency of an array elements using array_count_values is given below.

PROGRAM

<?php

//function to count the frequency of the array
function Counting_frequency($array){
    return(array_count_values($array));
}
 
// Driver Code
$array = array(1,1,1,12,23,23,3,12);
print_r(Counting_frequency($array));
$new_array=array("plexinfo","is","among",
                 "the","top","websites","of","the","world");

echo nl2br("\r\n");
echo nl2br("\r\n");

print_r(Counting_frequency($new_array));

?>


OUTPUT:




EmoticonEmoticon