嗨,我试图在php中创建一个函数,检查当前的一天,如果商店打开或关闭,返回。这是我到目前为止所拥有的,它工作,但它是很长的,所以如果有人知道最短的路径,那么请帮助!
$today = date('w'); // today
$starting = "THUR"; //opening day
$closing = "MON"; //closing day
$openday = date("w", strtotime($starting)); //coverting to number
$closeday = date("w", strtotime($closing)); // coverting to number
//checking if closing day is greater than opening day
if($openday < $closeday ){
//checking if today lies between starting and closing day
if($today > $openday && $today <= $closeday ){
$stat = 'Opened'; //if today lies between starting day and ending day then Opened
}
else{
$stat = 'Closed'; //else Closed
}
}
// if closing day is less than opening day
else{
//checking if today lies between opening day and friday
if($today > $openday && $today <= 6){
$stat = 'Opened';
}
//checking if today lies between sunday and closeday
else if( $today > 0 && $today <= $closeday ){
$stat = 'Opened';
}
else{
$stat = 'Closed'; // else Closed
}
}如果周四至周一开盘休市,这一天就会回来。如果你知道怎么做,那么请帮帮我。
发布于 2021-12-25 10:18:21
如果你知道你关门的日子(这是你必须做的),为什么不这样做呢?
$closed=array(
date('w',strtotime('Tuesday')),
date('w',strtotime('Wednesday'))
);
$status=in_array( date('w'),$closed ) ? 'Closed' : 'Open';
printf('We are "%s" on %s', $status, date('l') );今天的产出是:
We are "open" on Saturdayhttps://stackoverflow.com/questions/70479222
复制相似问题