如何填充上一年值(2016)选择的DropDown作为选定的默认值?使用PHP从下拉菜单中选择动态值
<?php
\t $last_year = date ("Y");
\t print "<select>";
\t for($i = 2004; $i <= $last_year; $i++) {
\t \t echo "<option selected=\"$last_year\" value=\"$i\">$i</option>\n";
\t };
\t print "</select>";
?>
谢谢!
我发现下面的链接类似的要求和解决方案。 http://stackoverflow.com/questions/34206981/php-loop-for-year-dropdown –
旁注:'echo'使用一个较少的字符,然后'打印'(更多的手指应变)。您可以在此问答中看到差异http://stackoverflow.com/questions/1647322/whats-the-difference-between-echo-print-and-print-r-in-php和http://stackoverflow.com/问题/ 7094118/reference-comparison-phps-print-and-echo - 如果'打印'你真正想使用的东西,那么你的权力就越大。 –