Jump to content

NoahJay

New Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by NoahJay

  1. im only a novice and im not so great with foreach loops, im not quite sure what I need to do im afraid
  2. Hello World! I'm Noah from Northern and Central Indiana, ive been coding minor projects for over 15 years.... man I wish I had found this site sooner
  3. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.