Leap Year Check in PHP

Description: Checks if the supplied year is a leap year.
Tested Platform: PHP 7+
Language: PHP
// The year is a leap year if it is divisible by 4 (evenly) and is either 
// divisible by 400 (again evenly) or not by 100. 1900 was not a leap year, but 
// 2000 was because it was divisible by 400 even though it was.

function isLeapYear($year) {
    return ((($year % 4) == 0) && ((($year % 400) == 0) || (($year % 100) != 0)));
}

Posted: March 18, 2023

Return to the snippets listing