我尝试从当天起6天内存储,但是我在这里没有什么困难,如何在$week的每个周期内保存所有下一个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)
这不是直接靠自己做数学的:
原文链接:https://www.f2er.com/php/140006.html$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'); }