What is the best way to remove duplicate entries in a PHP array while shifting the remaining entries?

When removing duplicate entries in a PHP array while shifting the remaining entries, one approach is to use a combination of array_unique() and array_values(). The array_unique() function removes duplicate values from an array, and then array_values() reindexes the array numerically. This way, the remaining entries are shifted to fill in the gaps left by the removed duplicates.

// Sample PHP array with duplicate entries
$array = [1, 2, 2, 3, 4, 4, 5];

// Remove duplicate entries and shift remaining entries
$array = array_values(array_unique($array));

// Output the modified array
print_r($array);