0
$months = array();
$first = strtotime("first day this month");
for ($i = 1; $i <= 6; $i++) {
array_push($months, date('F', strtotime("-$i month", $first)));
}
var_dump($months);
今天運行時,此代碼不能正常工作(3月份)PHP日期月未正確計算
輸出:
array(6) {
[0]=>
string(5) "March"
[1]=>
string(7) "January"
[2]=>
string(8) "December"
[3]=>
string(8) "November"
[4]=>
string(7) "October"
[5]=>
string(9) "September"
}
哪裏是2月?
可能重複[PHP DateTime ::修改加入和減去幾個月](http://stackoverflow.com/questions/3602405/php-datetimemodify-adding-and-subtracting-months) –
我沒有使用DateTime也沒有使用DateTime我正在使用本月的最後一天嗎? – morissette
該答案解釋了您的問題中的所有內容 –