What are some common methods in PHP to remove duplicate entries from an array while also deleting both values?

When dealing with an array in PHP that contains duplicate entries, we may want to remove these duplicates while also deleting both occurrences of the duplicate values. One common method to achieve this is by using a combination of array_unique() and array_diff() functions. First, we use array_unique() to remove duplicate values from the array, then we use array_diff() to find the difference between the original array and the array with unique values, resulting in an array with only the duplicate values.

// Original array with duplicate values
$array = [1, 2, 3, 2, 4, 5, 3, 6, 7, 8, 7];

// Remove duplicate values while also deleting both occurrences
$uniqueValues = array_unique($array);
$duplicateValues = array_diff($array, $uniqueValues);

print_r($duplicateValues);