How do I count occurrence of duplicate items in array

I would like to count the occurrence of each duplicate item in an array and end up with an array of only unique/non duplicate items with their respective occurrences.
Ankur Rajput
Asked 13-05-2020
44

Answer (1)
Using following code you get result $array = array(12,43,66,21,56,43,43,78,78,100,43,43,43,21); $vals = array_count_values($array); print_r($vals); Result: No. of NON Duplicate Items: 7 Array ( [12] => 1 [43] => 6 [66] => 1 [21] => 2 [56] => 1 [78] => 2 [100] => 1 );
Deepak Sharma
Asked 16-07-2018
45 Likes
Comments
Write comment

Submit your answer