如何在我的日期函数中添加 2014 - PHP


How to add 2014 in my date function - PHP?

我目前发现这个日期函数工作正常(不记得我在哪里找到它),但它显示从 2013 年开始的所有日、月和年。问题是现在我需要人们也能够从下拉列表中选择 2014。不太确定我应该编辑什么来添加它。

感谢您的任何帮助...代码:

function date_dropdown($year_limit = 0){
   $daynow = date("d");
   $monthnowtxt = date('F');
   $monthnow = date('m');
   $yearnow = date("20y");
   $html_output = '<div id="date_select" >'."'n";
   $html_output .= '<label for="date_day">Date of Longplay</label>'."'n";
    /*days*/
   $html_output .= '<select name="date_day" id="day_select"><option  ="selected" value="' . $daynow . '">' . $daynow . '</option>'."'n";
   for ($day = 1; $day <= 31; $day++) {
       $html_output .= '<option>' . $day . '</option>'."'n";
   }
  $html_output .= '</select>'."'n";
    /*months*/
  $html_output .= '<select name="date_month" id="month_select" ><option selected="selected" value="' . $monthnow . '">' . $monthnowtxt . '</option>'."'n";
  $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  for ($month = 1; $month <= 12; $month++) {
      $html_output .= '               <option value="' . $month . '">' . $months[$month] . '</option>'."'n";
   } 
   $html_output .= '</select>'."'n";
   /*years*/
   $html_output .= '<select name="date_year" id="year_select"><option ="selected" value="' . $yearnow . '">' . $yearnow . '</option>'."'n";
   for ($year = 1900; $year <= (date("Y") - $year_limit); $year++) {
           $html_output .= '               <option>' . $year . '</option>'."'n";
   }
   $html_output .= '</select>'."'n";
   $html_output .= '</div>'."'n";
   return $html_output;
  }

此方法调用为您提供 2014:

date_dropdown(-1);
这是

您需要更改的位

for ($year = 1900; $year <= (date("Y") - $year_limit); $year++)

date('Y')将于2013年回归

date('Y')+1将于2014年回归

for ($year = 1900; $year <= ((date("Y")+1) - $year_limit); $year++)

不得不说我不喜欢你包含的功能,可能有更干净、更灵活的方法来做它所做的事情。

更改此设置

for ($year = 1900; $year <= (date("Y") - $year_limit); $year++)

对此

for ($year = 1900; $year <= ((date("Y")+1) - $year_limit); $year++)

更改for循环

for ($year = 1900; $year <= (date("Y") - $year_limit); $year++)

for ($year = 1900; $year <= $year_limit); $year++)

并通过一个比 2014 年更伟大的论点......