How to count same value in array using php

If you want to get duplicate values count in an array,this method can be use easily.It will display array values all count.

The array_count_values() function counts all the values of an array.

$array = array("A","B","C","A","C");
print_r(array_count_values($array));

Output

Array ( [A] => 2 [B] => 1 [C] => 2 ) 

Leave a Reply

Your email address will not be published. Required fields are marked *