位置: 编程技术 - 正文

PHP数组函数array_unique()的用法(php的数组函数)

编辑:rootadmin
array_unique

推荐整理分享PHP数组函数array_unique()的用法(php的数组函数),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:php array数组,php数组函数有哪些,php数组函数 菜鸟,php数组函数有哪些,php数组函数有哪些,php数组函数有哪些,php数组函数 菜鸟,php数组函数大全,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4 >= 4.0.1, PHP 5)

array_unique — 移除数组中重复的值

说明 array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )

array_unique() 接受 array 作为输入并返回没有重复值的新数组。

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

Note: 当且仅当 (string) $elem1 === (string) $elem2 时两个单元被认为相同。就是说,当字符串的表达一样时。 第一个单元将被保留。

参数

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.

返回值 PHP数组函数array_unique()的用法(php的数组函数)

Returns the filtered array.

更新日志

版本 说明 5.2. 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.

范例

Example #1 array_unique() 例子

<?php$input=array("a"=>"green","red","b"=>"green","blue","red");$result=array_unique($input);print_r($result);?>

以上例程会输出:

Example #2 array_unique() 和类型

<?php$input=array(4,"4","3",4,3,"3");$result=array_unique($input);var_dump($result);?>

以上例程会输出:

参见

array_count_values() - 统计数组中所有的值出现的次数

注释

Note: Note that array_unique() is not intended to work on multi dimensional arrays.

PHP数组函数array_walk()的用法 array_walk(PHP4,PHP5)array_walk使用用户自定义函数对数组中的每个元素做回调处理说明boolarray_walk(array&$array,callable$funcname[,mixed$userdata=NULL])将用户自定义函数fu

PHP数组函数array_values()的用法 array_values(PHP4,PHP5)array_values返回数组中所有的值说明arrayarray_values(array$input)array_values()返回input数组中所有的值并给其建立数字索引。参数input数组。返回

PHP数组函数array_walk_recursive()的用法 array_walk_recursive(PHP5)array_walk_recursive对数组中的每个成员递归地应用用户函数说明boolarray_walk_recursive(array&$input,callable$funcname[,mixed$userdata=NULL])将用户自定

本文链接地址:https://www.jiuchutong.com/biancheng/281048.html 转载请保留说明!

上一篇:PHP数组函数compact()的用法(php数组函数输出《咏雪》里有多少"片"字)

下一篇:PHP数组函数array_walk()的用法(php数组函数,选班长)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络