$start_date = new DateTime();// 开始的日期
$end_date = new DateTime();// 结束的日期
$end_date->modify(date('Y-m-d', time()));//日期循环最后定位在当日
$interval = new DateInterval('P1W'); // 一周的时间间隔
$data = [];
while ($start_date <= $end_date) {
$week_start = clone $start_date;
$week_start->modify('this week'); // 获取本周的周一
$week_end = clone $week_start;
$week_end->modify('+6 days'); // 获取本周的周日
$week = array(
'start_date' => $week_start->format('Y/m/d'),
'end_date' => $week_end->format('Y/m/d')
);
$data[] = $week; // 将本周的开始日期和结束日期存储到数组中
$start_date->add($interval);
}
$data = array_reverse($data);//将结果倒序