How to use Conditional Statements In PHP

The basic method involves using conditional statements to check the leap year conditions.

PHP




<?php
  
function isLeapYear($year) {
    if (($year % 4 == 0 && $year % 100 != 0) 
        || ($year % 400 == 0)) {
        return true;
    } else {
        return false;
    }
}
  
// Driver code
$year = 2024;
  
if (isLeapYear($year)) {
    echo "Leap Year";
} else {
    echo "Not a Leap Year";
}
  
?>


Output

Leap Year

PHP Program to Check a Given Year is a Leap Year or Not

A leap year is a year that is divisible by 4, except for years that are divisible by 100. However, years divisible by 400 are also considered leap years. In this article, we will explore different approaches to create a PHP program that determines whether a given year is a leap year or not.

Similar Reads

Using Conditional Statements

The basic method involves using conditional statements to check the leap year conditions....

Using date Function

...

Contact Us