$days = [];
for ($i = 0; $i <= 7; $i++) { // 需要天數調整上限
$days[] = date('Y-m-d', strtotime("-$i day"));
}
print_r($days);
Array
(
[0] => 2014-03-21
[1] => 2014-03-20
[2] => 2014-03-19
[3] => 2014-03-18
[4] => 2014-03-17
[5] => 2014-03-16
[6] => 2014-03-15
[7] => 2014-03-14
)
strtotime('+1 week')、strtotime('first day of this month')、strtotime('last day of -1 month') 等自然語言時間極其強大。DateTime / DatePeriod 物件導向 API (PHP 5.3+),時區處理更安全、鏈式調用更優雅。