3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start_time = new DateTime('09:00'); $close_time = new DateTime('21:00'); $periods = new DatePeriod($start_time, new DateInterval('PT30M'), $close_time); foreach ($periods as $period) { $times[] = $period->format('H:i'); } // DatePeriod excludes the end time $times[] = $close_time->format('H:i'); print_r($times);
Output for 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Array ( [0] => 09:00 [1] => 09:30 [2] => 10:00 [3] => 10:30 [4] => 11:00 [5] => 11:30 [6] => 12:00 [7] => 12:30 [8] => 13:00 [9] => 13:30 [10] => 14:00 [11] => 14:30 [12] => 15:00 [13] => 15:30 [14] => 16:00 [15] => 16:30 [16] => 17:00 [17] => 17:30 [18] => 18:00 [19] => 18:30 [20] => 19:00 [21] => 19:30 [22] => 20:00 [23] => 20:30 [24] => 21:00 )

preferences:
138.37 ms | 409 KiB | 5 Q