Checks a flat list for duplicate values, returning true
if duplicate values exists and false
if values are all unique.
Use count()
and array_unique()
to check $items
for duplicate values.
代码实现
function hasDuplicates($items)
{
return count($items) > count(array_unique($items));
}
使用样例
hasDuplicates([1, 2, 3, 4, 5, 5]); // true