What is the best approach to deduplicate data in PHP arrays based on specific values?

When deduplicating data in PHP arrays based on specific values, one approach is to iterate through the array and use a secondary array to keep track of unique values. As each value is encountered, check if it already exists in the secondary array. If it does not, add it to the secondary array and keep it in the resulting array.

<?php
// Original array with duplicate values
$array = [1, 2, 3, 2, 4, 1, 5, 6, 3];

// Secondary array to keep track of unique values
$uniqueValues = [];

// Resulting array with deduplicated values
$deduplicatedArray = [];

foreach ($array as $value) {
    if (!in_array($value, $uniqueValues)) {
        $uniqueValues[] = $value;
        $deduplicatedArray[] = $value;
    }
}

print_r($deduplicatedArray);
?>