PHP array_unique()Functions
Complete PHP Array Reference Manual
Examples
Remove duplicate values from an array:
<?php
$a=array("a"=>"red","b"=>"green","c"=>"red");
print_r(array_unique($a));
?>
$a=array("a"=>"red","b"=>"green","c"=>"red");
print_r(array_unique($a));
?>
Run example »
Definition and Usage
The array_unique() function is used to remove duplicate values from an array. If two or more array values are the same, only the first value is kept, and the other values are removed.
Note:The retained array will maintain thefirstarray item's key name type.
Syntax
array_unique(array)
| Parameter | Description |
|---|---|
| array | Required. Specifies the array. |
| sortingtype | Optional. Specifies the sorting type. Possible values:
|
Technical Details
| Return value: | Returns the filtered array. |
|---|---|
| PHP version: | 4.0.1+ |
| Changelog: | In PHP 5.2.10,sortingtypethe default value was changed back to SORT_STRING. In PHP 5.2.9,sortingtypethe default value was changed to SORT_REGULAR. In versions before this,sortingtypethe default value was SORT_STRING. |
Complete PHP Array Reference Manual Other extensions