function get_week($time = '', $format='Y-m-d'){ $time = $time != '' ? $time : time(); //获取当前周几 $week = date('w', $time); $weekname = array('周一','周二','周三','周四','周五','周六','周日'); //星期日排到末位 if(empty($week)){ $week=7; } $date = []; for ($i=0; $i<7; $i++){ $date_time = date($format ,strtotime( '+' . $i+1-$week .' days', $time)); $date[$i]['date'] = $date_time; $date[$i]['time'] = strtotime($date_time); $date[$i]['week'] = $weekname[$i]; } return $date; }
打印结果
Array ( [0] => Array ( [date] => 2019-06-17 [time] => 1560700800 [week] => 周一 ) [1] => Array ( [date] => 2019-06-18 [time] => 1560787200 [week] => 周二 ) [2] => Array ( [date] => 2019-06-19 [time] => 1560873600 [week] => 周三 ) [3] => Array ( [date] => 2019-06-20 [time] => 1560960000 [week] => 周四 ) [4] => Array ( [date] => 2019-06-21 [time] => 1561046400 [week] => 周五 ) [5] => Array ( [date] => 2019-06-22 [time] => 1561132800 [week] => 周六 ) [6] => Array ( [date] => 2019-06-23 [time] => 1561219200 [week] => 周日 ) )