<?php
$month = array();
for ( $i=1; $i<13; $i++ ) {
$month = date('m', mktime(0,0,0,$i,2,2000));
$sel = ( $i == date('n') ? ' selected="selected"' : '');
$options1[] = "<option value=\"{$month}\" {$sel}>{$month}</option>";
}
$options_list1 = join("", $options1);
echo "<select name=\"month\" >{$options_list1}</select>";
for ( $j=1; $j<32; $j++ ) {
$theday = date('d', mktime(0,0,0,0,$j,2000));
$sel = ( $j == date('d') ? ' selected="selected"' : '');
$options2[] = "<option value=\"{$theday}\" {$sel}>{$theday}</option>";
}
$options_list2 = join("\r\n", $options2);
echo "<select name=\"day\" >{$options_list2}</select>";
for ( $k=1960; $k<2016; $k++ ) {
$theyear = date('Y', mktime(0,0,0,0,2,$k));
$sel1 = ( $k == date('Y') ? ' selected="selected"' : '');
$options3[] = "<option value=\"{$theyear}\" {$sel1}>{$theyear}</option>";
}
$options_list3 = join("\r\n", $options3);
echo "<select name=\"day\" >{$options_list3}</select>";
?>
它是日、月和年的下拉菜单。日期和月份工作正常,但年份不是,在这一年我的循环工作不正常,今天是 2013 年,它正在选择 2012 年。任何人都可以帮助我吗?