PHP array_unique () function
Examples
Remove duplicate values in the 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));
?>
Running instance »
Definition and Usage
array_unique () function is used to remove duplicate values in the array. If two or more of the same array of values, retaining only the first value, other values are removed.
Note: The array will be retained to keep the firstitem in the array type keys.
grammar
array_unique( array )
参数 | 描述 |
---|---|
array | 必需。规定数组。 |
sortingtype | 可选。规定排序类型。可能的值:
|
technical details
return value: | Returns an array filtered. |
---|---|
PHP version: | 4.0.1+ |
Update log: | In PHP 5.2.10, the default value is changed back to sortingtype SORT_STRING. In PHP 5.2.9, the default value sortingtype changed SORT_REGULAR. Prior to this version, sortingtype defaults SORT_STRING. |
![PHP Array Reference](/images/up.gif)