[英]How do I display the upcoming alternating Thursdays in PHP and have them not overwrite each other each week
I'm trying to write some php that outputs the delivery days for a store.我正在尝试编写一些 php 来输出商店的交货日期。
They deliver goods every Thursday, but to 2 locations and they alternate those locations weekly, so this Thursday they will deliver to Foo and the following Thursday they will deliver to Bar, then the following thursday they will deliver to Foo again and so on....他们每周四送货,但会送货到 2 个地点,他们每周轮换这些地点,所以这个星期四他们会送货到 Foo,下周四他们会送货到 Bar,然后下个星期四他们会再次送货到 Foo,依此类推。 ..
Ideally I'd like to output:理想情况下,我想要 output:
The next delivery to Foo is: [date] The next delivery to Bar is: [date]到 Foo 的下一次交付是:[日期] 到 Bar 的下一次交付是:[日期]
Apologies for my code, I've just started learning about time/datetime stuff and it confuses me!为我的代码道歉,我刚刚开始学习时间/日期时间的东西,这让我很困惑!
I've have this which I based of another example:我有这个,我基于另一个例子:
<?php
$nextThursday= strtotime("next Thursday");
$secondThursday=strtotime("next Thursday",$nextThursday);
echo "The next delivery to Foo is: <strong>" . date("l-jS-F",$nextThursday) . "</strong>, Please order before 7am on " . date("l-jS-F",$nextThursday) . " to ensure delivery.<br>";
echo "The next delivery to Foo is: <strong>" . date("l-jS-F",$secondThursday) . "</strong>, Please order before 7am on " . date("l-jS-F",$secondThursday) . " to ensure delivery.<br>";
?>
But wasn't sure how to get this example working as once the current date gets to 'nextThursday' it will then say the delivery dates around the wrong way.但是不确定如何让这个例子工作,因为一旦当前日期到达“nextThursday”,它就会以错误的方式说出交货日期。 Is there a simple way around this?有解决这个问题的简单方法吗? Do I need to use a number of weeks somehow?我需要以某种方式使用数周吗?
Thanks in advance提前致谢
I believe you would like to generate a time schedule for delivery (say next 10 weeks?).我相信您想生成一个交付时间表(比如说接下来的 10 周?)。
Assuming that you want to print the delivery schedule for the next 10 weeks' thursday and first delivery is go to 'Foo'.假设您要打印接下来 10 周星期四的交货时间表,并且第一次交货是 go 到“Foo”。 In that case we may在那种情况下,我们可能
<?php
// initalize to today first
$xdate = strtotime("Today");
for ($index=0; $index <10; $index++){
$xdate = strtotime("Next Thursday", $xdate);
echo "The next delivery to ". ($index%2==0 ? 'Foo':'Bar') ." is: <strong>" . date("l-jS-F",$xdate) . "</strong>, Please order before 7am on " . date("l-jS-F",$xdate) . " to ensure delivery.<br><br>";
}
You may see the effect at the following sandbox link:您可以在以下沙盒链接中看到效果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.