php – 闰年和非闰年进入单独的表
作者:互联网
这段代码将显示从1991年到2100年的闰年和非闰年,我试图在闰年和非闰年制作一个表,但我失败了.
如何以表格格式或网格系统中引入它?这是为了学术研究.
<!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,css,bootstrap-modal,html,leap-year 来源: https://codeday.me/bug/20190710/1427917.html