根据今天的日期的 PHP 日期范围
任何人都可以想出一种更好的方法来将其写在循环中并获得相同的结果吗?
$today = date('l');
if($today == 'Wednesday'){
$min = date('l-m-d-y');
$max = date('l-m-d-y', strtotime('+4 days'));
}else if($today == 'Thursday'){
$min = date('l-m-d-y', strtotime('-1 days'));
$max = date('l-m-d-y', strtotime('+3 days'));
}else if($today == 'Friday'){
$min = date('l-m-d-y', strtotime('-2 days'));
$max = date('l-m-d-y', strtotime('+2 days'));
}else if($today == 'Saturday'){
$min = date('l-m-d-y', strtotime('-2 days'));
$max = date('l-m-d-y', strtotime('+1 days'));
}else if($today == 'Sunday'){
$min = date('l-m-d-y', strtotime('-3 days'));
$max = date('l-m-d-y');
}
echo $min . ' - ' . $max;
Can anyone think of a better way of writing this out in a loop and getting the same result?
$today = date('l');
if($today == 'Wednesday'){
$min = date('l-m-d-y');
$max = date('l-m-d-y', strtotime('+4 days'));
}else if($today == 'Thursday'){
$min = date('l-m-d-y', strtotime('-1 days'));
$max = date('l-m-d-y', strtotime('+3 days'));
}else if($today == 'Friday'){
$min = date('l-m-d-y', strtotime('-2 days'));
$max = date('l-m-d-y', strtotime('+2 days'));
}else if($today == 'Saturday'){
$min = date('l-m-d-y', strtotime('-2 days'));
$max = date('l-m-d-y', strtotime('+1 days'));
}else if($today == 'Sunday'){
$min = date('l-m-d-y', strtotime('-3 days'));
$max = date('l-m-d-y');
}
echo $min . ' - ' . $max;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您希望周六分钟内为 -3,周日分钟内为 -4。无论如何,这就是这个想法:
I assumed you wanted -3 in the min on Saturday and -4 on Sunday. Anyway, this is the idea:
可以将其存储在一个数组中,以日期为键,+/-x 天作为值。
could store it in an array with the day as the key and the +/-x days as the values.