提供下面的代碼,輸出是(見下文)。我的問題是爲什麼在2009/11/01之後,在2009/11/30和2009/12/30之前,而不是2009/12/01。從2009/06/01〜2009/11/01沒有問題。本月php的循環日期
輸出
2009/06/01
2009/07/01
2009/08/01
2009/09/01
2009/10/01
2009/11/01
2009 /30分之11
2009/12/30
我的代碼
<?php
$startdate = "2009/06/01";
$enddate = "2009/12/31";
$start = strtotime($startdate);
$end = strtotime($enddate);
$currentdate = $start;
while($currentdate < $end)
{
$cur_date = date('Y/m/d',$currentdate);
$month = date('m', $currentdate);
$year = date('Y', $currentdate);
$monthLength = daysOfMonth($month, $year);
$currentdate += $monthLength;
echo $cur_date . "<br />";
}
function daysOfMonth($month, $year)
{
return (86400 * date("t", strtotime($year."-".$month."-01")));
}
?>
是阿爾瓦羅的答案是否足夠?您應該將其標記爲「已接受」或對仍存在問題進行評論。 – philfreo 2009-12-26 04:37:12