array_unique
移除数组中重复的值
&reftitle.description;
arrayarray_unique
arrayarray
intsort_flagsSORT_STRING
array_unique 接受
array 作为输入并返回没有重复值的新数组。
注意键名保留不变。array_unique
先将值作为字符串排序,然后对每个值只保留第一个遇到的键名,接着忽略所有后面的键名。这并不意味着在未排序的
array 中同一个值的第一个出现的键名会被保留。
当且仅当
(string) $elem1 === (string) $elem2 时两个单元被认为相同。就是说,当字符串的表达一样时。
第一个单元将被保留。
&reftitle.parameters;
array
输入的数组。
sort_flags
The optional second parameter sort_flags
may be used to modify the sorting behavior using these values:
Sorting type flags:
SORT_REGULAR - compare items normally
(don't change types)
SORT_NUMERIC - compare items numerically
SORT_STRING - compare items as strings
SORT_LOCALE_STRING - compare items as
strings, based on the current locale.
&reftitle.returnvalues;
Returns the filtered array.
&reftitle.changelog;
&Version;
&Description;
5.2.10
Changed the default value of sort_flags back to
SORT_STRING.
5.2.9
Added the optional sort_flags defaulting
to SORT_REGULAR. Prior to 5.2.9, this function used to sort
the array with SORT_STRING internally.
&reftitle.examples;
array_unique 例子
"green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>
]]>
&example.outputs;
green
[0] => red
[1] => blue
)
]]>
array_unique 和类型
]]>
&example.outputs;
int(4)
[2] => string(1) "3"
}
]]>
&reftitle.seealso;
array_count_values
&reftitle.notes;
Note that array_unique is not intended to
work on multi dimensional arrays.