How can the user optimize the code to efficiently handle different types of holiday periods within the loop?

The user can optimize the code by creating an array of holiday periods and checking if the current date falls within any of those periods within the loop. This way, the code can efficiently handle different types of holiday periods without the need for multiple if statements.

// Array of holiday periods
$holidays = array(
    array('start' => '2022-12-24', 'end' => '2022-12-26'), // Christmas holiday
    array('start' => '2023-01-01', 'end' => '2023-01-02'), // New Year holiday
    // Add more holiday periods as needed
);

foreach ($dates as $date) {
    $isHoliday = false;
    foreach ($holidays as $holiday) {
        if ($date >= $holiday['start'] && $date <= $holiday['end']) {
            $isHoliday = true;
            break;
        }
    }
    
    if ($isHoliday) {
        echo "$date is a holiday<br>";
    } else {
        echo "$date is a regular day<br>";
    }
}