Exclude dates from a php DatePeriod output

This was a really interesting problem. I couldn’t make your method work, but here’s another approach that I think uses more readable code and has the holidays built in for any year.

I tested it and at least it works for memorial day. :wink:

 * @param string $curYear - current year, e.g. "2019"
 * @return array - array of holiday timestamps
 */

function getHolidays($curYear) {
    $holidays = array();
    $holidays[] = strtotime("january $curYear third monday"); //marthin luther king jr.day
    $holidays[] = strtotime("february $curYear third monday"); //presidents day
    $holidays[] = strtotime(easter_date($curYear)); // easter
    $MDay = date('Y-m-d', strtotime("may $curYear first monday")); // memorial day (set below)
      $eMDay = explode("-", $MDay);
      $year = $eMDay[0];
      $month = $eMDay[1];
      $day = $eMDay[2];

      while ($day <= 31) {
          $day = $day + 7;
      }
      if ($day > 31) {
          $day = $day - 7;
      }

    $holidays[] = strtotime($year . '-' . $month . '-' . $day); // memorial day
    $holidays[] = strtotime("september $curYear first monday");  //labor day
    $holidays[] = strtotime("october $curYear third monday"); //columbus day
    $TH = date('Y-m-d', strtotime("november $curYear first thursday")); // thanks giving (set below)
      $eTH = explode("-", $TH);
      $year = $eTH[0];
      $month = $eTH[1];
      $day = $eTH[2];

      while ($day <= 30) {
          $day = $day + 7;
      }
      if ($day > 30) //watch out for the days in the month November only have 30
      {
          $day = $day - 7;
      }

    $holidays[] = strtotime($year . '-' . $month . '-' . $day); // Thanksgiving

    return $holidays;
    
}

/**
 * @param int $t - timestamp
 * @param $holidays - array of holiday timestamps
 * @return bool - true for holidays or false
 */
function isHoliday($t, $holidays) {
    return (in_array($t, $holidays));
}

$curYear = date("Y");//current year
$holidays = getHolidays($curYear);
$weekdayNames = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday');
$output = "";

/* Get day of year */
$today = date('z');
$output .= "\n<br>Today is day# " . $today;

/* $weekdays will be an array of upcoming weekdays that are not holidays */
$weekdays = array();

for ($days=$today; $days < (int) $today + 20; $days++) {
    /* Get timestamp for given day */
    $timestamp = strtotime("January 1st +" . ($days) . " days");

    /* If $timestamp is non-holiday weekday, add it to the $weekdays array */
    if (in_array(strftime("%A",$timestamp), $weekdayNames)) {
        if (! isHoliday($timestamp, $holidays)) {
            $weekdays[] = $timestamp;
        }
    }
}

/* Display the list of non-holiday weekdays */
foreach ($weekdays as $weekday) {
    $output .= "\n<br>" . strftime("%A %c", $weekday);
}

return $output;