3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '11am-3pm'; list($begin, $end) = explode('-', $str); $begin = new DateTime($begin); $end = new DateTime($end); $end = $end->modify('+1 hour'); $interval = new DateInterval('PT1H'); $daterange = new DatePeriod($begin, $interval, $end); $result = array_map(fn($d) => $d->format('ga'), iterator_to_array($daterange)); print_r($result);
Output for 7.4.0 - 7.4.33, 8.0.1 - 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] => 11am [1] => 12pm [2] => 1pm [3] => 2pm [4] => 3pm )

preferences:
118.68 ms | 407 KiB | 5 Q