How can together time periods be filtered and output in PHP?

To filter and output time periods together in PHP, you can use the DateTime class to create DateTime objects for the start and end times, and then use a loop to iterate through the time periods. You can then output the time periods in the desired format.

$startTime = new DateTime('2022-01-01 08:00:00');
$endTime = new DateTime('2022-01-01 17:00:00');

$interval = new DateInterval('PT1H'); // 1 hour interval
$periods = new DatePeriod($startTime, $interval, $endTime);

foreach ($periods as $period) {
    echo $period->format('Y-m-d H:i:s') . ' - ' . $period->add($interval)->format('Y-m-d H:i:s') . '<br>';
}