PHP查找下一个开放日

时间:2018-09-28 05:24:35

标签: php arrays laravel

我有一个具有开放时间的SQL表。它存储星期几,开放时间,关闭时间和关闭时间

我的问题是,在PHP中,如何计算一周中第二天的营业时间?

希望如此。

enter image description here

PHP代码

foreach($value->openTimes as $time){
                if($time->open_day == strtolower(date("l")) && $time->closed != 1){
                    $daySet = 1;
                    $value['next_open'] = 'Today';
                    $value['next_open_start'] = $time->open_start_time;
                    $value['next_open_end'] = $time->open_end_time;
                    break;
                }

                //IF ITS NOT OPEN TODAY FIND THE NEXT NEARESR DAY IT IS OPEN
            }

欢呼

1 个答案:

答案 0 :(得分:0)

您对此有何看法?

$days = [
    'Today',
    'Tomorrow'
];

foreach ($value->openTimes as $time) {
    for ($i = 0; $i < 7; $i++) {
        if ($time->open_day == strtolower(date('l', strtotime("+$i day"))) && $time->closed != 1) {
            $daySet = $i + 1;
            $value['next_open'] = !empty($days[$i]) ? $days[$i] : date('l');
            $value['next_open_start'] = $time->open_start_time;
            $value['next_open_end'] = $time->open_end_time;
            break;
        }
    }
}