Find duplicates in an array with PHP

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

/**
* Takes an array and returns an array of duplicate items
*/
function get_duplicates( $array ) {
	return array_unique( array_diff_assoc( $array, array_unique( $array ) ) );
}

7 thoughts on “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!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s