程序运行截图如下:
代码如下:
例子一:
- <?php
- $year = 2000;
- echo "<h2>闰年的判断</h2>";
- echo "<p>输入的年份: " . $year . " 年</p>";
-
- if($year % 4 == 0){
-
- echo "<p>" . $year . "是润年</p>";
- }
- else{
-
- echo "<p>" . $year . "是平年</p>";
- }
-
- ?>
例子二:
- <?php
- $year = 2020;
- $ret = ($year % 4) == 0 ? '平年' : '闰年';
- ?>
-
- <h2>闰年的判断</h2>
- <p>输入的年份: <?php echo $year ?>年</p>
- <p><?php echo $year . "是" . $ret ?></p>