A Sample PHP script to remove all the duplicate values from an array. A running example to remove duplicate array values using PHP
Use PHP array_unique() function to remove all the duplicate values form an array. This function takes input of an array and return another array without duplicate values.
Here is an sample example:
| <?php $input = array("a" => "green", "green", "blue", "b" => "green", "red"); // Remove duplicate elements from an array $result = array_unique($array); print_r($result); ?> |
Expected output:
Array
(
[a] => green
[1] => blue
[2] => red
)