Home > OS >  best practice to check if a collection has duplicate values?
best practice to check if a collection has duplicate values?

Time:03-31

what is the best practice to check if a collection has duplicate values. example:

$collection = collect([1, 2, 3, 4, 5]);
$collection->isDuplicate() // false

$collection = collect([1, 2, 2, 4, 5]);
$collection->isDuplicate() // true

CodePudding user response:

You can use $collection->duplicates()->isNotEmpty(); to check if there are duplicates.

  • Related