如何从PHP中的数组中删除所有重复? [英] How can I remove ALL duplicates from an array in PHP?

查看:147
本文介绍了如何从PHP中的数组中删除所有重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想指出所有您复制问题猎人的<一个href=\"http://stackoverflow.com/questions/307650/how-to-remove-duplicate-values-from-an-array-in-php\">this问题没有完全回答我的问题。

First of all, I'd like to point out to all you duplicate question hunters that this question does not fully answer my question.

现在,我有一个数组。我们会说数组是阵列(1,2,2,3,4,3,2)

Now, I've got an array. We'll say that the array is array(1, 2, 2, 3, 4, 3, 2)

我需要删除重复项。不只是重复之一,但的所有的,这样的结果将是阵列(1,4)

I need to remove the duplicates. Not just one of the duplicates, but all, so that the result will be array(1, 4)

我看着 array_unique(),但这只会导致阵列(1,2,3,4)

I looked at array_unique(), but that will only result in array(1, 2, 3, 4)

任何想法?

推荐答案

您可以使用 array_unique 和array_diff_assoc 和的 和array_diff

You could use the combination of array_unique, array_diff_assoc and array_diff:

array_diff($arr, array_diff_assoc($arr, array_unique($arr)))

这篇关于如何从PHP中的数组中删除所有重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆