So I have this code:
$companyHolidays = Holiday::all();
$newholiday = [];
foreach($companyHolidays as $holiday){
$newholiday[] = [
'id' => $holiday->id,
'title' => $holiday->title,
'start' => $holiday->start,
'end' => $holiday->end,
'parsed_company_holidays' => CarbonPeriod::create($holiday->start, $holiday->end)
];
}
$customHoliday = [];
foreach ($newholiday as $holiday) {
$customHoliday[] = $holiday['parsed_company_holidays']->toArray();
}
while ($i < $eventRepeats) {
// add one week
$eventStart->addDays(7);
if (in_array($eventStart->translatedFormat('Y-m-d'), $holidaysArray)) {
continue;
}
// todo: this here is the issue
if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {
continue;
}
echo '<div class="text-primary font-normal mt-6 mb-2">'.$count++.'. Termin</div>';
echo '<div class="bg-dark-gray rounded-lg border-l-4">';
echo '<div class="p-3">';
echo $eventStart->translatedFormat('l, d. F Y, H:i');
echo ' - ';
echo $eventEnd->translatedFormat('H:i');
echo '</div></div>';
// increase iteration
$i++;
}
if I do dd($customHoliday);
I get the following:
Inside it are these:
So for comparing the dates inside the if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {
it would probably look like the $holidaysArray
:
But I cannot figur out how to merge all the arrays and then make the dates inside the $customHoliday
comparable like the $holidaysArray
(based on YASUMI API)
because I already implemented the holiday API and it continue
the loop, if in the array:
if (in_array($eventStart->translatedFormat('Y-m-d'), $holidaysArray)) {
continue;
}
but with the current way it does not work with this:
if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {
continue;
}