Example 1 — Remove Duplicate Values
Clean up a list that contains repeated colors.
<?php
$colors = ["red", "blue", "red", "green", "blue"];
$unique = array_unique($colors);
echo implode(", ", $unique), PHP_EOL;
echo "Keys: ", implode(",", array_keys($unique)), PHP_EOL; How It Works
- The list has five items with "red" and "blue" repeated.
- array_unique() keeps the first "red" and first "blue" and drops the repeats.
- The result has three values: red, blue and green.
- The surviving keys are 0, 1 and 3, so the numbering has a gap.

