获取周一和周日的日期

$week = date('w') == 0 ? 7 : date('w');
$Sunday = strtotime('today -' . ($week - 1) . 'day');
$Monday = strtotime('today +' . (8 - $week) . 'day -1second');
dump(date('m-d H:i:s', $Sunday)); // string(14) "07-11 00:00:00"
dump(date('m-d H:i:s', $Monday)); // string(14) "07-17 23:59:59"

指定周内的时间戳

还是在之前的代码上更新

$index = 0; //0则代表本周
$week = date('w') == 0 ? 7 : date('w');
$start = strtotime('today ' . (- ($week - 1) + (7 * $index)) . 'day');
$end = strtotime('today ' . ((8 - $week) + (7 * $index)) . 'day -1second');
return [$start, $end];
dump(date('m-d H:i:s', $start));  //string(14) "07-11 00:00:00"
dump(date('m-d H:i:s', $end));  //string(14) "07-17 23:59:59"

其中$index的值,正数1代表当前周的后一周,-1则代表当前周的前一周,0则表示当前周