PHP array_unique function
Last Updated: February 15, 2022
array_unique — Remove duplicate elements from the array
Syntax
array_unique(array $array, int $flags = SORT_STRING): array
Supports (PHP 4 , PHP 5, PHP 7, PHP 8)
Parameters
Parameter | Description |
array | target array |
flags |
The optional second parameter Sorting type flags:
|
Return Value
returns the array without duplicates
Example
$input = array("a", "b", "c", "c", "b");
$output = array_unique($input);
print_r($output);
Output
Array ( [0] => a [1] => b [2] => c )