Skip to content
PHP Logo

What function in PHP can be used to filter out duplicate values in an array?

When dealing with arrays in PHP, you may encounter the need to filter out duplicate values to ensure each element is unique. One way to achieve this is by using the `array_unique()` function in PHP. This function takes an array as input and returns a new array with only unique values, removing any duplicates. By using `array_unique()`, you can easily clean up your array and ensure that each value is distinct.

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

// Filter out duplicate values
$uniqueArray = array_unique($array);

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