PHP array_unique() Function

PHP array_unique Function


Definition :

The array_unique() function removes duplicate values from an array.

If multiple values are found equal, the first value and its key will be kept and others will be removed.

Syntax

The basic syntax of the array_unique() function is given with:

    array_unique(arraysort_flags);

Parameters

The array_unique() function accepts the following parameters.

Parameter Description
array Required. Specifies the array to work on.
sort_flags

Optional. Specifies how array items s hould be compared. Possible values are:

  • SORT_STRING – Compare items as strings. Default value.
  • SORT_NUMERIC – Compare items numerically.
  • SORT_REGULAR – Compare items normally (don't change types).
  • SORT_LOCALE_STRING – Compare items as strings, based on the current locale.

Example : following example to show remove  duplicate values from an array

Output : 

Array
(
    [a] => web
    [b] => designing
    [c] => house
)