Find duplicates in an array with PHP

Here is a function to find duplicate items in an array.

[source language=“php“]
/**
* Takes an array and returns an array of duplicate items
*/
function get_duplicates( $array ) {
return array_unique( array_diff_assoc( $array, array_unique( $array ) ) );
}
[/source]

7 Kommentare zu „Find duplicates in an array with PHP

  1. This is really great . I was looking for a fast solution to this problem and your solution works great.Nice job!!!

Kommentar verfassen