我有以下问题: 我需要创建一个从1990年到2014年的2D表。如果那一年是闰年,那么右侧是正确的,如果没有,则右侧:
这是我到目前为止所做的:
<?php
echo "<table>";
for($i=0;$i<1;$i++) {
echo "<tr>";
echo "<td>" . "Leto je prestopno" . "</td>";
echo "<td>" . "Leto ni prestopno" . "</td>";
echo "</tr>";
for($j=0;$j<12;$j++){
}
}
echo "<table>";
?>
答案 0 :(得分:0)
可以试试这个
function is_leap_year($year)
{
return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));
}
echo '<table border="1">';
echo '<tr><th>Leap Year</th><th>Not Leap Year</th></tr>';
for($i = 1990; $i < 2015; $i++){
if(is_leap_year($i)){
$left_td = $i;
$right_td = '-';
}else{
$left_td = '-';
$right_td = $i;
}
echo '<tr><td>'.$left_td.'</td><td>'.$right_td.'</td></tr>';
}
echo '</table>';