我相信这是一个非常明显的问题,有一个函数可以做到这一点,但我似乎找不到它.在PHP中,我想知道数组中是否有重复项,并且尽可能高效.我不想像array_unique
那样删除它们,我也不特别想运行array_unique
并将其与原始数组进行比较,看看它们是否相同,因为这似乎效率很低.就性能而言,"预期条件"是数组没有重复项.
我只是希望能够做一些像这样的事情
if (no_dupes($array))
// this deals with arrays without duplicates
else
// this deals with arrays with duplicates
Is there any obvious function I'm not thinking of?
How to detect duplicate values in PHP array?
has the right title, and is a very similar question, however if you actually read the question, he's looking for array_count_values.