我想要这种链接
<li><a href="arhiva?year=2009">Kamp 2009/10</a></li>
<li><a href="arhiva?year=2007">Kamp 2007/08</a></li>
但是明年我想自动添加新的链接
<li><a href="arhiva?year=2011">Kamp 2011/12</a></li>
如何使用 PHP 循环来做到这一点for
,我有变量$today = date("Y");
干得好 :
<?php
$currentYear = date("Y"); // same as your $today variable
for ($i = 2007; $i < $currentYear; $i++) {
$nextYear = date("y",mktime(0, 0, 0, date("m"), date("d"), $i+1));
echo "<li><a href=\"arhiva?year=$i\">Kamp $i/$nextYear</a></li>";
}
我错过了什么吗?
<?php
for ($i = 2007; $i <= $today; $i++) {
echo "<li><a href=\"arhiva?year=$i\">Kamp $i/08</a></li>";
}
?>