How can PHP be used to dynamically generate a select list of time intervals for different shop opening hours?

To dynamically generate a select list of time intervals for different shop opening hours in PHP, you can create a function that takes the opening and closing hours as parameters and then generates a list of time intervals at a specified interval (e.g., every 30 minutes). This function can be called to populate a select dropdown in an HTML form.

<?php
function generateTimeIntervals($openingHour, $closingHour, $interval = 30) {
    $options = '';
    $currentTime = strtotime($openingHour);
    $closingTime = strtotime($closingHour);

    while ($currentTime < $closingTime) {
        $time = date('H:i', $currentTime);
        $options .= "<option value='$time'>$time</option>";
        $currentTime += $interval * 60;
    }

    return $options;
}
?>

<select name="opening_time">
    <?php echo generateTimeIntervals('09:00', '18:00'); ?>
</select>