如何从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)))