How does PHP handle leap year calculations?
In PHP, leap year calculations can be handled by using the `date()` function to check if a specific year is a leap year. Leap years occur every 4 years, except for years that are divisible by 100 but not by 400. By utilizing the `date('L', strtotime("$year-01-01"))` function, we can determine if a given year is a leap year or not.
function isLeapYear($year) {
return date('L', strtotime("$year-01-01")) ? true : false;
}
$year = 2024;
if (isLeapYear($year)) {
echo "$year is a leap year.";
} else {
echo "$year is not a leap year.";
}