Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$period = (new DatePeriod(new DateTime('11:00:00'), new DateInterval('PT1H'), new DateTime('17:00:00')))->getIterator();
//$period = Carbon\CarbonPeriod::create('11:00:00', '1 hour', '17:00:00');
$data = [];
while ($period->valid()) {
$current = $period->current();
$period->next();
if ($next = $period->current()) {
$data[] = $current->format('h:i A') . ' - ' . $next->format('h:i A');
}
}
echo implode(PHP_EOL, $data);