PHP array_unique() Function
Complete PHP Array Reference Manual
Example
Remove duplicate values from an array:
"red","b"=>"green","c"=>"red"); print_r(array_unique($a)); ?>Run Example »
Definition and Usage
The array_unique() function removes duplicate values from an array. If two or more array values are equal, only the first value is kept and the others are removed.
Note:The retained array will keep the key type of thefirstarray item.
Syntax
array_unique(
array
)
| Parameters | 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, the default value ofsortingtype was changed back to SORT_STRING. |
在 PHP 5.2.9 中,*sortingtype* 的默认值改为 SORT_REGULAR。在这之前的版本,*sortingtype* 的默认值为 SORT_STRING。 |
Complete PHP Array Reference Manual