Home > Backend Development > PHP Tutorial > php数组去重复数据示例_PHP

php数组去重复数据示例_PHP

WBOY
Release: 2016-06-01 11:56:11
Original
867 people have browsed it

以数字开头的重复数据如:
复制代码 代码如下:
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)); 
}

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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template