Skip to main content

Remove Duplicate Values of an Array in PHP

Duplicate values in arrays can be a nuisance when trying to manipulate or iterate through them. Removing them can make the process more efficient.

The PHP array_unique() function takes an input and returns a new, improved version of the original with all duplicate values removed. This means you can use it to remove any repeat occurrence from your data! This function makes it easy to work with arrays that may have duplicates by ensuring that each value in the returned array is unique.

In addition, the order of the values in the original array is preserved in the returned array. To use this function, simply pass in the array as the only argument. The function will then return the new array without any duplicate values. This can be especially useful when working with large arrays or when you need to be sure that there are no duplicate values in an array.

$array = ["Samsung Galaxy Note 10", "Apple iPhone 13 Pro", "Samsung Galaxy Note 10", "Apple iPhone 13 Pro Max", "Apple iPhone 13 Pro"];
$result = array_unique($array);

By continuing to use the site, you agree to the use of cookies.