IT & Programming

Check leap year with php

This function accepts number format year as a parameter and returns true if year is a leap year else it returns false.

Function

function isLeapYear($year) {
    
	if (($year % 4) != 0){

		return false;
	}	

	if ($year % 400 == 0) {

		return true;
		
	} else if (($year > 1582) and ($year % 100 == 0)) {

		return false;
	}
}

Calling The function

echo isLeapYear(2000);

Output

1

Leave A comment

Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *