我试图每30分钟创建一个时隙,现在我得到以下结果:
Array
(
[0] => 09:00AM - 09:30AM
[1] => 09:31AM - 10:01AM
[2] => 10:02AM - 10:32AM
[3] => 10:33AM - 11:03AM
[4] => 11:04AM - 11:34AM
[5] => 11:35AM - 12:05PM
[6] => 12:06PM - 12:36PM
[7] => 12:37PM - 13:07PM
[8] => 13:08PM - 13:38PM
}
但是我想知道每个时隙的“可用时间”或“预定时间”如何解决? 这是我的餐桌结构
表名-“预订”
id shop_id booking_start_time booking_close_time
1 3 10:00AM 11:00AM
我尝试使用以下代码,如何显示结果为“可用”或“已预订”
$duration="30";
$break="1";
$stTime="09:00";
$enTime="19:00";
$start = new DateTime($stTime);
$end = new DateTime($enTime);
$interval = new DateInterval("PT" . $duration. "M");
$breakInterval = new DateInterval("PT" . $break. "M");
for ($intStart = $start;
$intStart < $end;
$intStart->add($interval)->add($breakInterval)) {
$endPeriod = clone $intStart;
$endPeriod->add($interval);
if ($endPeriod > $end) {
$endPeriod=$end;
}
$periods[] = $intStart->format('H:iA') .
' - ' .
$endPeriod->format('H:iA');
}
print_r($periods);