<?
// Write aprogram to find a leap year using PHP
// argument UDF and fmod().
?>
<?php
function isLeapYear($year)
{ // Check if the year is a leap year
if (fmod($year, 4) == 0)
{ if (fmod($year, 100) == 0)
{ if (fmod($year, 400) == 0)
{
return true;
// Divisible by 400, it's a leap year
}
else
{
return false;
}
}
else
{
return true;
}
}
else
{
return false;
}
}
// Example usage
$years = [2000, 2001, 2004, 1900, 2020, 2021];
foreach ($years as $yr) {
if (isLeapYear($yr)) {
echo "<br><b>$yr</b> is a leap year.";
} else {
echo "<br><b>$yr</b> is NOT a leap year.";
}
} ?>