Home  >  Article  >  php教程  >  php-Arrays函数-array_unique-移除数组中重复的值

php-Arrays函数-array_unique-移除数组中重复的值

WBOY
WBOYOriginal
2016-06-13 10:49:50996browse

array_unique() 移除数组中重复的值

【功能】
         该函数将返回以指定数组为基础的没有重复值的新数组,键名保持不变
         该函数先将值作为字符串排序,然后对每个值只保留第一个遇到的键名,
         接着忽略所有后面的键名
         这并不意味着在未排序的数组中同值的第一个出现的键名被保留
【使用范围】
         php4>=4.0.1、php5.
【使用】
         mixed array_unique( array array  )
         array/必需/即将进行函数处理的原始数组
【示例】
[php]
$input=array('c'=>"green",'aed','b'=>'green','blue','bed'); 
var_dump(array_unique($input)); 
/*
array(4) {
  ["c"]=>
  string(5) "green"
  [0]=>
  string(3) "aed"
  [1]=>
  string(4) "blue"
  [2]=>
  string(3) "bed"
}
*/ 

 


摘自 zuodefeng的笔记

Statement:
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 admin@php.cn