PHP array_unique() Function

PHP array_unique() Function

The array_unique() function in PHP removes the duplicate values from the specified array.

Syntax

Parameter

array(required)– This array represents the first input array.

sort_flags (optional)– This parameter is used to modify the sorting behavior. The various sorting type flags are as follows:

  • SORT_REGULAR – It compares the items normally (don’t change types)
  • SORT_NUMERIC – It compares the items numerically
  • SORT_STRING (Default Value) – It compares the items as strings
  • SORT_LOCALE_STRING – It compares the items as strings, based on the current locale.

Return

This function returns the filtered array by removing the duplicate values for the array.

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output

Example 5

Output