I have a function here from https://toroguapo.com/gf-hero/articles/calculating-holidays-for-a-given-year-in-php
function get_holidays(int $year): array {
$holidays = [
// Fixed holidays
'new_years_day' => new DateTime("$year-01-01"),
'juneteenth' => new DateTime("$year-06-19"),
'independence_day' => new DateTime("$year-07-04"),
'veterans_day' => new DateTime("$year-11-11"),
'christmas' => new DateTime("$year-12-25"),
'Valentines Day' => new DateTime("$year-02-14"),
// Variable holidays
'martin_luther_king_day' => new DateTime(
"third Monday of January $year"
),
'washington_day' => new DateTime(
"third Monday of February $year"
),
'memorial_day' => new DateTime(
"last Monday of May $year"
),
'labor_day' => new DateTime(
"first Monday of September $year"
),
'columbus_day' => new DateTime(
"second Monday of October $year"
),
'thanksgiving_day' => new DateTime(
"fourth Thursday of November $year"
),
];
// Inauguration Day, every 4th year
if ($year % 4 === 0) {
$inauguration_day = new DateTime("$year-01-20");
if ($inauguration_day->format('l') === 'Sunday') {
$inauguration_day->modify('+1 day');
}
$holidays['inauguration_day'] = $inauguration_day;
}
// Easter
$easter = new DateTime("$year-03-21");
$easter->modify('+' . easter_days($year) . ' days');
$holidays['easter'] = $easter;
return $holidays;
}
function list_holidays(DateTimeInterface $date): bool {
$year = (int) $date->format('Y');
$date_formatted = $date->format('Y-m-d');
foreach (get_holidays($year) as $holiday) {
$holiday_formatted = $holiday->format('Y-m-d');
echo $holiday_formatted;
}
}
Basically what im trying to do is run a foreach to loop and for every holiday echo out "Holiday Name is Date" I know im close but cant quite figure it out, anyone willing to help me get this working? Id be eternally grateful.