array_unique in PHP

Synatx of array_unique

array array_unique(array array[, int sort_flags])

Creates and returns an array containing each element in the given array. If any values are duplicated, the later values are ignored. The sort_flags optional argument can be used to alter the sorting methods with constants: SORT_REGULAR, SORT_NUMERIC, SORT_STRING (default), and SORT_LOCALE_STRING. Keys from the original array are preserved

Example of array_unique in PHP

$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);


    [a] => green
    [0] => red
    [1] => blue

Leave a Comment