How to remove duplicate values from an array in PHP

Ian picture Ian · Nov 21, 2008 · Viewed 250.7k times · Source

How can I remove duplicate values from an array in PHP?

Answer

Jeremy Ruten picture Jeremy Ruten · Nov 21, 2008

Use array_unique().

Example:

$array = array(1, 2, 2, 3);
$array = array_unique($array); // Array is now (1, 2, 3)