0

我一直在研究这个问题,但不明白为什么我会收到错误。警告引用该行:if ($i==$break_date['month'])并且仅在升级到 PHP 5.4 后仍然存在

下面是一个非常有用的动态生成日期选择器的函数。任何见解将不胜感激。

function date_picker($name, $date, $startyear='2005', $endyear='2020') {  

$break_date = date_parse($date);


if($startyear==NULL) $startyear = date("Y")-100;
if($endyear==NULL) $endyear=date("Y")+50; 

$months=array('','01 January','02 February','03 March','04 April','05 May',
'06 June','07 July','08 August', '09 September','10 October','11 November','12 December');

// Month dropdown
$html="<select name=\"".$name."_month\" style='width: 22%;'>";
$html.="<option value=''>Month</option>";
for($i=1;$i<=12;$i++)
{
   if ($i==$break_date['month']) 
   { 
     $month_selected = "selected";
    } else {
     $month_selected = "";
   }
   $html.="<option value='$i' $month_selected>$months[$i]</option>";
}
$html.="</select> ";

// Day dropdown
$html.="<select name=\"".$name."_day\" style='width: 22%;'>";
$html.="<option value=''>Day</option>";    
for($i=1;$i<=31;$i++)
{
   if ($i==$break_date['day']) 
   { 
     $day_selected = "selected";
    } else {
     $day_selected = "";
   }    
   $html.="<option value='$i' $day_selected>$i</option>";
}
$html.="</select> ";

// Year dropdown
$html.="<select name=\"".$name."_year\" style='width: 22%;'>";
$html.="<option value=''>Year</option>";
for($i=$startyear;$i<=$endyear;$i++)
{ 
   if ($i==$break_date['year']) 
   { 
     $year_selected = "selected";
    } else {
     $year_selected = "";
   }         
  $html.="<option value='$i' $year_selected>$i</option>";
}
$html.="</select> ";

return $html;
}
4

0 回答 0