gpt4 book ai didi

php - 从今天算起接下来的 6 天?

转载 作者:行者123 更新时间:2023-12-03 00:32:52 25 4
gpt4 key购买 nike

我尝试存储从当天开始的接下来 6 天,但我有点困惑如何在 $weekOfdays 中存储所有接下来的 6 天。有没有简单的函数可以做到这一点?

<?php
$weekOfdays = array();
$day = date('l');
$weekOfdays[] = $day;
$day = strtotime($day);

$next = strtotime("+6 day",$day);
$weekOfdays[] = date("l",$next);
var_dump($weekOfdays);
// output
// array (size=2)
// 0 => string 'Monday' (length=6)
// 1 => string 'Sunday' (length=6)
?>

我想看到数组是这样的

array (size=7)
0 => string 'Monday' (length=6)
1 => string 'Tuesday' (length=7)
2 => string 'Wednesday' (length=9)
3 => string 'Thursday' (length=8)
4 => string 'Friday' (length=6)
5 => string 'Saturday' (length=8)
6 => string 'Sunday' (length=6)

最佳答案

这里直接依赖于您自己进行数学计算:

$days   = [];$period = new DatePeriod(    new DateTime(), // Start date of the period    new DateInterval('P1D'), // Define the intervals as Periods of 1 Day    6 // Apply the interval 6 times on top of the starting date);foreach ($period as $day){    $days[] = $day->format('l');}

关于php - 从今天算起接下来的 6 天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36393942/

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