gpt4 book ai didi

php - 前 30 天通过一个循环

转载 作者:行者123 更新时间:2023-12-01 22:36:38 24 4
gpt4 key购买 nike

我需要编写一个循环,以下列格式输出从昨天算起的最近 30 天:

2014-02-02
2014-02-03
2014-02-04
...
2014-03-04

我想我需要像这样使用循环:

for ($i=0; $i<=30; $i++) {
echo $date;
}

而且我知道我可以找到 30 天前的开始日期

$startDate = date('Y-m-d', time() - (60 * 60 * 24 * -31) );

不确定将所有这些部分放在一起(下午咖啡因剥夺)......

最佳答案

使用strtotime()

for($i = 30; $i > 0; $i--)
{

echo date("Y-m-d", strtotime("-$i days"));

}

关于php - 前 30 天通过一个循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22209972/

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