Remove Duplicates from PHP Array: Ultimate Guide
You can use the array_unique function to remove duplicate values from an array. This function will return a new array that only contains unique values from the original array.
Example usage:
<?php
$array = array(1, 2, 3, 2, 4, 3);
$array = array_unique($array);
print_r($array);
?>
Output result:
Array
(
[0] => 1
[1] => 2
[2] => 3
[4] => 4
)
In the example above, the duplicate values 2 and 3 in the original array were removed, and a new array was returned.