Skip to content
Advertisement

How to detect duplicate values in PHP array?

I am working with a one dimensional array in PHP. I would like to detect the presence of duplicate values, then count the number of duplicate values and out put the results. For example, given the following array:

JavaScript

I would like to print:

JavaScript

Any advice on how to approach this problem?

Thanks.

Mike

Advertisement

Answer

You can use array_count_values function

JavaScript

will output

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement