gpt4 book ai didi

php - 如何在php中创建一个包含前四个星期的下拉列表

转载 作者:行者123 更新时间:2023-12-04 18:22:57 25 4
gpt4 key购买 nike

如何在 php.ini 中创建本周和前几周最多四个的下拉导航。
enter image description here

$date = '04/24/20012';
$ts = strtotime($date);
$year = date('o', $ts);
$week = date('W', $ts);
for($i = 1; $i <= 7; $i++) {
$ts = strtotime($year.'W'.$week.$i);
print date("m/d/Y l", $ts) . "\n";
}

此代码用当前周填充下拉列表,但我想要的是用前四个星期填充下拉列表。

最佳答案

for ($i = 0; $i <= 4; $i++)
{
$weeks[] = date('m/d/Y', strtotime("-$i week", time()));
}

给出:
array
0 => string '04/23/2012' (length=10)
1 => string '04/16/2012' (length=10)
2 => string '04/09/2012' (length=10)
3 => string '04/02/2012' (length=10)
4 => string '03/26/2012' (length=10)

编辑:如果您想要范围,请执行以下操作:
for ($i = 0; $i <= 4; $i++)
{
$k = $i - 1;
$weeks[] = date('m/d/Y', strtotime("-$i week")) . ' - ' .
date('m/d/Y', strtotime("-$k week -1 day"));
}

给出:
array
0 => string '04/23/2012 - 04/29/2012' (length=23)
1 => string '04/16/2012 - 04/22/2012' (length=23)
2 => string '04/09/2012 - 04/15/2012' (length=23)
3 => string '04/02/2012 - 04/08/2012' (length=23)
4 => string '03/26/2012 - 04/01/2012' (length=23)

关于php - 如何在php中创建一个包含前四个星期的下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10278605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com