简体   繁体   English

如何在 PHP 中显示即将到来的交替星期四,并让它们每周不互相覆盖

[英]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在那种情况下,我们可能

  • use a loop使用循环
  • make sure the delivery date is updated to next thursday at every iteration确保在每次迭代时将交付日期更新为下周四
  • use Modulus operator (%) to "switch" from Foo to Bar and so on使用模数运算符 (%) 从 Foo 到 Bar 等“切换”
<?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:您可以在以下沙盒链接中看到效果:

https://onlinephp.io/c/d1c98 https://onlinephp.io/c/d1c98

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要在Php中隐藏字段,并在单击每个字段的按钮后将其显示 - I need to hide fields in Php and have them display after I click a button for each of them 如何在PHP中让价值彼此跟随? - How to have value follow each other in PHP? PHP Laravel如何对每个月的日期进行分组并显示 - PHP Laravel How to group dates for each month and display them 如何在图表中显示一周中的每天数据? - How do I show each day data of the week in graph? 我如何将图像彼此相邻放置而不会破裂 - How do I put the images next to each other without them breaking 我是否必须针对PHP脚本中的每个错误显示特定的错误消息(这些错误消息包含在Javascript代码中) - Do I have to display specific error message for each error in PHP script(these error messages are included in Javascript code) 如何在PHP中“添加”字符串-不是串联,而是“添加”它们。 (好像每个字符都是以36为基数的数字) - How do I “add” strings in PHP - not concatenate, but “add” them. (as if each character was a base 36 numbers) 我如何选择和显示来自同一用户的所有行,而在彼此之间却是php - how can I select and display all the rows from the same user, underneath each other with php 如何在PHP中显示当前一周的开始和结束日期? - How do I display the start and end date of the current week in PHP? 如何让这个 woocommerce 单选框水平显示,而不是垂直显示? - How do I make this woocommerce radio checkbox to display horizontally next to each other instead of vertically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM