Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?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);
Copy Clear