Skip to content
Advertisement

Tag: count

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. Here is my code; BUT I don’t where am going wrong! Answer array_count_values, enjoy 🙂 Result:

How to run array_filter recursively in a PHP array?

Given the following array $mm When I run count(array_filter($mm)) I get 3 as result since it is not recursive. count(array_filter($mm), COUNT_RECURSIVE) also will not do because I actually need to run the array_filter recursively, and then count its result. So my question is: how do I recursively run array_filter($mm) in this case? My expected result here would be 4. Please

Advertisement