How can the in_array function be used to remove duplicate values in PHP arrays?

When dealing with PHP arrays containing duplicate values, the in_array function can be used to check if a value already exists in the array. By using this function, we can iterate through the array, checking each value against a temporary array to remove duplicates.

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

// Temporary array to store unique values
$uniqueArray = [];

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

// $uniqueArray now contains only unique values
var_dump($uniqueArray);