php - 闰年和非闰年分表

标签 php html css bootstrap-modal leap-year

此代码将显示从 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/

相关文章:

javascript - 缩放网页然后单击后退按钮会更改上一页的背景大小

c# - 我如何在 javascript 警告对话框中添加标题文本

javascript - 数据动画 Bootstrap 轮播效果不起作用

javascript - 自动完成不起作用......(AJAX+PHP+HTML+JS)

html - 需要找到文件源

javascript - 使用 php codeigniter 将计算出的 javascript 变量值传递到文本字段

c# - MVC - 将动态添加的控件绑定(bind)到模型中的 List<T>

jquery - 具有 2 种图像尺寸(横向和纵向)的幻灯片

php - 无法使用 PHP 脚本连接到本地托管 mysql

javascript - javascript 变量内的 html 和 php