Find Duplicate Array Elements in PHP

in previous post we have learn how to count duplicate values, Here we will learn how to find duplicate element and extract them from array. Sometimes we need to get only the duplicate elements from arrays. PHP provide many array functions, we used some of them .first we will get unique array with help of array_unique method then we will extract difference of arrays with help of array_diff_assoc and finally we will fire array_unique function to get duplicate values of array.

Checkout other tutorial of Duplicate Records,

We used following combination of all listed methods.

array_unique(array_diff_assoc($aray, array_unique($aray)));

Simple Example: