PHP Array Function : array_count_values()

The array_count_values() function is used to count all the values of an array. The syntax of array_count_values() is as follows :
 array_count_values(array);
Where array represents the name of array. The function returns an associative array, where the keys are the original array's values, and the values are the number of occurrences.

Example :
<?php

  $my_arr = array(100, 200, 150, 200, "PHP", "MYSQL", "PHP", 200, 150);

  $new_arr = array_count_values($my_arr);

  foreach($new_arr as $key => $value) {
    echo $key . " : " . $value . "<br/>";
  }

?>
Output :

100 : 1
200 : 3
150 : 2
PHP : 2
MYSQL : 1


Next Topic :