What are some alternative approaches to handling date highlighting in a PHP calendar, aside from the current implementation?

The current implementation of date highlighting in a PHP calendar may involve manually setting CSS classes for each highlighted date, which can be cumbersome and not easily scalable. An alternative approach is to dynamically generate the CSS classes based on a predefined list of highlighted dates, making it easier to manage and update the highlighted dates.

<?php
// Define an array of highlighted dates
$highlighted_dates = ['2022-01-01', '2022-02-14', '2022-03-17'];

// Function to check if a date is highlighted
function isHighlightedDate($date, $highlighted_dates) {
    return in_array($date, $highlighted_dates);
}

// Loop through calendar dates and dynamically generate CSS classes
for ($i = 1; $i <= 31; $i++) {
    $date = date('Y-m-d', strtotime("2022-01-$i"));
    $class = isHighlightedDate($date, $highlighted_dates) ? 'highlighted' : '';
    echo "<div class='calendar-date $class'>$i</div>";
}
?>