Home  >  Article  >  php教程  >  php数组去重复数据示例

php数组去重复数据示例

WBOY
WBOYOriginal
2016-06-13 09:41:361251browse

以数字开头的重复数据如:

复制代码 代码如下:


Array (
[0] => 100
[k1] => 100
[1] => 2123
[k2] => 2123  ) 


该方法可以将以数字为key的值去掉,先将数组按照key倒序排序,然后用array_unique的方法将重复的值去掉。
不能适用于下面的情况:不同的key值存在相同的value的情况

复制代码 代码如下:


function array_unique_value($arr = array()){ 
    array_multisort($arr, SORT_DESC, array_keys($arr)); 
    print_r(array_unique($arr)); 
}

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