PHP array_unique() Function is used to remove duplicate values from an array. PHP array_unique() function is PHP built-in function.
Syntax :
array_unique(array $array, int $flags = SORT_STRING);
Parameter,
$array : Required. It is input array.
$flags : Optional. It is sorting type flags.It specifies how to compare the array elements/items.
SORT_STRING - Default. Compare items as strings
SORT_REGULAR - Compare items normally (don't change types)
SORT_NUMERIC - Compare items numerically
SORT_LOCALE_STRING - Compare items as strings based on current locale.
Return : It returns array containing unique values of an array. An array_unique() Function removes all duplicate values except first appearance value.
All values keep same preserved keys.
Let's see below example to understand php array_unique() Function in details.
Comments