PHP获取上周所有日期,PHP获取当前时间前一周七天具体日期方法:


/**
* 获取本周所有日期
*/
function get_week($time = '', $format='Y-m-d'){
  $time = $time != '' ? $time : time();
  $date = [];
  for ($i=1; $i<=7; $i++){
    $date[$i] = date($format ,strtotime( '+' . $i-7 .' days', $time));
  }
  return $date;
}

调用及输出:


print_r(get_week());

Array
(
  [1] => 2018-11-12
  [2] => 2018-11-13
  [3] => 2018-11-14
  [4] => 2018-11-15
  [5] => 2018-11-16
  [6] => 2018-11-17
  [7] => 2018-11-18
)