I want to retrieve all duplicated entries from a array. Is this possible in PHP?
array( 1 => '1233', 2 => '12334', 3 => 'Hello', 4 => 'hello', 5 => 'U' );
I want to return an array with just the duplicate value: “hello”.
Desired output array:
array( 1 => 'Hello', 2 => 'hello' );
And a case-insensitive solution: $iArr = array_map('strtolower', $arr); $iArr = array_intersect($iArr, array_unique(array_diff_key($iArr, array_unique($iArr)))); array_intersect_key($arr, $iArr);
The array_diff() (manual) function can be used to find the difference between two arrays: $array1 = array(10, 20, 40, 80); $array2 = array(10, 20, 100, 200); $diff = array_diff($array1, $array2); // $diff = array(40, 80, 100, 200);
function get_duplicates ($array) { return array_unique( array_diff_assoc( $array, array_unique( $array ) ) ); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With