php数组函数序列之array_unique() - 去除数组中重复的元素值

高洛峰
Release: 2023-03-04 20:24:01
Original
1342 people have browsed it

array_unique() 定义和用法 
array_unique() 函数移除数组中的重复的值,并返回结果数组。 

当几个数组元素的值相等时,只保留第一个元素,其他的元素被删除。 

返回的数组中键名不变。 

语法 
array_unique(array) 
参数 描述 
array 必需。规定输入的数组。 

说明 
array_unique() 先将值作为字符串排序,然后对每个值只保留第一个遇到的键名,接着忽略所有后面的键名。这并不意味着在未排序的 array 中同一个值的第一个出现的键名会被保留。 

提示和注释 
注释:被返回的数组将保持第一个数组元素的键类型。 

例子 

"Cat","b"=>"Dog","c"=>"Cat"); 
print_r(array_unique($a)); 
?>
Copy after login

输出: 

Array ( [a] => Cat [b] => Dog )

更多php数组函数序列之array_unique() - 去除数组中重复的元素值相关文章请关注PHP中文网!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!