I am using the Laravel framework, I have an array of dates where I want to check if there are two same dates exist. The array is this
array:5 [▼
0 => "2020-04-11"
1 => "2020-04-11"
2 => "2020-04-12"
3 => "2020-04-13"
4 => "2020-04-21"
]
I have written the following function to check, it works but I curious if there is any better way to achieve this because I have to extend it soon so there will be more nested loops.
private function validateFlyingDatesAreOverlapping($flyingDates)
{
foreach ($flyingDates as $key => $datePick) {
$datePickInstance = Carbon::parse($datePick)->startOfDay();
foreach ($flyingDates as $index => $dateCompare) {
$dateCompare = Carbon::parse($dateCompare)->startOfDay();
if ($key != $index) {
$result = $datePickInstance->eq($dateCompare);
if ($result) {
return true;
}
}
}
}
return false;
}