此代码将显示从 1991 年到 2100 年的闰年和非闰年,我试图为闰年制作表格 1,为非闰年制作表格,但我失败了。
如何以表格格式或网格系统将其引入?这是为了学术研究。
<!DOCTYPE html>
<html>
<head>
<title>Leap Year</title>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<?php
function isLeap($year) {
return ((($year % 4) == 0) && ((($year % 100) != 0)));
}
for($year=1991; $year<=2100; $year++)
{
If (isLeap($year))
{
$leap="$year : LEAP YEAR <br/>";
//echo "<div class='col-sm-12'>" . $leap . "</div>";
echo $leap;
}
else
{
$nonLeap="$year : Not leap year <br/>";
//echo "<div class='col-sm-6'>" . $nonLeap ."</div>";
echo $nonLeap;
}
}
?>
</body>
</html>
最佳答案
您的 isLeap 函数有误。也可以引用这个post .
function isLeap($year) {
return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year % 400) == 0)));
}
for($year=1991; $year<=2100; $year++)
{
if (isLeap($year))
{
$leaps[] = $year;
}
else
{
$nonLeaps[] = $year;
}
}
echo '<table><tr>';
foreach($leaps as $y)
{
echo '<td>' . $y . '</td>';
}
echo '</tr></table>';
关于php - 闰年和非闰年分表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43820491/