php - php 显示 3 个日期:下周三、周六、周日(包括今天)
问题描述
目前我写了很长的代码:
if ($today_day == "Wednesday"){
//show today date, show next saturday date, show next sunday date
}elseif ($today_day == "Saturday"){
//show today date, show next Sunday date, show next Wednesday date
}elseif ($today_day == "Sunday"){
//show today date, show next Wednesday date, show next Saturday date
}else{
//show next Wednesday date, show next Saturday date, show next Sunday date
}
对此还有其他解决方案吗?我想缩短代码。
解决方案
在这里尝试以下解决方案:
if ($today_day == "Wednesday"){
//show today date, show next saturday date, show next sunday date
$today = date('Y-m-d');
$next_saturday = date('Y-m-d',strtotime("next saturday + 1 week"));
$next_sunday = date('Y-m-d',strtotime("next sunday + 1 week"));
}
elseif ($today_day == "Saturday"){
//show today date, show next Sunday date, show next Wednesday date
$today = date('Y-m-d');
$next_wednesday = date('Y-m-d',strtotime("next wednesday + 1 week"));
$next_sunday = date('Y-m-d',strtotime("next sunday + 1 week"));
}
elseif ($today_day == "Sunday"){
//show today date, show next Wednesday date, show next Saturday date
$today = date('Y-m-d');
$next_wednesday = date('Y-m-d',strtotime("next wednesday + 1 week"));
$next_saturday = date('Y-m-d',strtotime("next saturday + 1 week"));
}
else{
//show next Wednesday date, show next Saturday date, show next Sunday date
$next_saturday = date('Y-m-d',strtotime("next saturday + 1 week"));
$next_wednesday = date('Y-m-d',strtotime("next wednesday + 1 week"));
$next_sunday = date('Y-m-d',strtotime("next sunday + 1 week"));
}
推荐阅读
- php - Cron Job 超时:下载长视频的 PHP 脚本
- javascript - 带有控件属性的视频标签导致单元测试失败
- angular - 如何处理 FileReader 在 TypeScript 中返回 ArrayBuffer 或 String
- android - 如何使用 SelectAll 按钮更改所有 recyclerview 项目的背景?
- druid - 在 Druid 中编写自定义扩展
- pytorch - 手动更新与使用模型需要非常不同的学习率
- python - 如何使用 Python 中的长笛乐器从音符制作 MIDI 文件(music21 库)
- jquery - jQuery 验证错误放置和所需的文本放置
- tfs - TFS 备份作业挂起 - 我如何找到问题?
- php - 它在本地与 xampp 一起工作。登录有效,但注册无效