PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

array_unique

Tags: PHP 5.x PHP 7.x PHP 8.x

array_unique — Removes duplicate values from an array.

Description

array_unique(
    array $array,
int $flags = SORT_STRING
): array
Takes an input array and returns a new array without duplicate values.
Note that keys are preserved. If multiple elements compare equal under the given flags, then the key and value of the first equal element will be retained.

Note:Two elements are considered equal if and only if (string) $elem1 === (string) $elem2 i.e. when the string representation is the same, the first element will be used.

Parameters

array
The input array.
int
The optional sorting flags. It can be any combination of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_LOCALE_STRING, SORT_NATURAL, SORT_FLAG_CASE or SORT_NATURAL_CASE.

Return Values

Returns the filtered array.