Skip to content
PHP Logo

What is the function in PHP that can be used to remove duplicate values from an array?

To remove duplicate values from an array in PHP, you can use the `array_unique()` function. This function takes an array as input and returns a new array with only unique values, removing any duplicates. This can be useful when you want to ensure that each value in the array is unique.

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

// Remove duplicates
$uniqueArray = array_unique($array);

// Output the unique array
print_r($uniqueArray);