我正在编写一个函数,如果商店是否打开将输出给用户。
我写了一个名为is_store_open()的函数,其中包含一个名为$ day的变量,该变量将分配给它的当天。
让我们说是星期六。它找到了"星期六"并检查星期六的开放时间和结束时间。
我面临的问题是,商店周六午夜开放。然后,它不会在星期六检查案件。
相反将检查周日的情况。这不是我想要的,因为当它打开时仍会打开商店,周六"
我在下面编写了一个函数,用于检查前一天的结束时间是否大于当前时间。如果它是真的然后返回true,我想这应该解决问题。
但是当我写到它会给我一个错误,说$ saturday_close是未定义的。我猜它是因为它在switch语句中,并且它不等于那一天。
我对如何设置这一点感到有点困惑。如果有人有建议我会非常感谢你的帮助。谢谢!
function is_store_open(){
$set_time = strtotime("tomorrow"); // Lets just sat its Sunday for testing purposes
$day = date("l", $set_time);
$time_now = mktime("00", "00", "00"); // Now lets say the time now is 12:00am
switch ($day) {
case "Saturday":
$open = "11:00";
$saturday_close = "1:00";
break;
case "Sunday";
if($saturday_close > $time_now ){//If the $monday_close hours are greater then the current time return false the store is still open
return true;
} else {
$open = "2:00";
$close = "22:00";
}
break;
}
答案 0 :(得分:0)
class StoreOperationHours {
public $time_now;
public function __construct() {
//$this->time_now = mktime("2", "00", "00" ); // Now lets say the time now is 12:00am;
$this->time_now = mktime(date('H'), date('i'), date('s'));
}
public $SaturdayOpenHours = "11:00";
public $SaturdayClosingHours = "1:08:00";
public $SundayOpenHours = "11:00";
public $SundayCloseHours = "23:00";
public function IsStoreOpen() {
//$set_time = strtotime("tomorrow"); // Lets just sat its Sunday for testing purposes
$day = date("l", time());
switch ($day) {
case "Saturday":
$this->SaturdayOpenHours;
$this->SaturdayClosingHours;
break;
case "Sunday";
if(strtotime($this->SaturdayClosingHours) >= $this->time_now ){//If the $monday_close hours are greater then the current time return false the store is still open
return true;
} elseif($e) {
return false;
}
break;