30 seconds of PHP

  Back to Home

hasDuplicates

arraybeginner

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));
}