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

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

WBOY
WBOYOriginal
2016-07-13 17:51:21710browse

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的笔记

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478192.htmlTechArticlearray_unique() 移除数组中重复的值 【功能】 该函数将返回以指定数组为基础的没有重复值的新数组,键名保持不变 该函数先将值作为字符串...
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