PHP填充具有特定日期的下拉列表

时间:2011-05-31 14:44:22

标签: php forms strtotime

我希望在下一个星期五和星期六的日期中填写下拉列表。这是一种预订系统。我想我应该使用strtotime函数。 但是,我想订购此下拉菜单,以便如果用户在星期六尝试操作,则首先显示第一个星期六选项。 我想用

填充菜单
strtotime('friday');
strtotime('saturday');
strtotime('+1 weeks friday');
strtotime('+1 weeks saturday');
strtotime('+2 weeks friday');
strtotime('+2 weeks saturday');
strtotime('+3 weeks friday');
strtotime('+3 weeks saturday');

但显然如果在星期六使用它,这将无效。 (即下周五下周将显示在当前星期六之上)。任何人都可以提出一种解决方法吗?

对不起,如果这个问题很漫无问题,那就是漫长的一天:p

修改 为了澄清,我正在寻找一种方法来自动将列表排序更改为

strtotime('saturday');
strtotime('+1 weeks friday');
strtotime('+1 weeks saturday');
strtotime('+2 weeks friday');
strtotime('+2 weeks saturday');
strtotime('+3 weeks friday');
strtotime('+3 weeks saturday');
strtotime('+4 weeks friday');

如果用户在星期六运行脚本。 (即在列表中保留8个项目,第一个项目是下一个可用日期)。

1 个答案:

答案 0 :(得分:1)

我假设这个字符串传递给了strtotime()?

请勿使用“下周五”和“下周六”。说“下个星期五”总是会在之后的下一个星期五给你。只需使用“星期五”,如果今天是星期五,则返回与“今天”相同,否则返回与“下周五”相同。

要接下来的四个星期五和星期六这样做:

strtotime('friday');
strtotime('saturday');
strtotime('+1 weeks friday');
strtotime('+1 weeks saturday');
strtotime('+2 weeks friday');
strtotime('+2 weeks saturday');
strtotime('+3 weeks friday');
strtotime('+3 weeks saturday');