w3codeworld logo
  • Home
  • C
  • C++
  • Java
  • Python3
  • JavaScript
  • C#
  • PHP
  • Codeigniter
  • Laravel
  • Articles
  1. Home
  2. Articles
  3. PHP program to check leap year using the if-else and by using the switch case statement
  • PHP
  • Codeigniter
  • Laravel
  • C
  • C++
  • Java
  • Python3
  • JavaScript
  • C#

PHP program to check leap year using the if-else and by using the switch case statement

  • Author: Admin
  • Last Updated: 2020-12-18
  • Category: PHP

PHP program to check leap year using the if-else and by using the switch case statement. There are you will learn how to check a year is the leap year or not by using the if-else, and by using the switch case statement.

 

Samples of the leap years:

2000, 2004, ....., 2016, 2020 are the leap years

 

Let us consider the examples to understand this through the PHP programs:

1. PHP program to check leap year using the if-else statement:

<?php
// PHP program to check leap year
// using the if-else statement

$y = 1997;

if ($y % 400 == 0) {
    echo $y . " is the leap year.\n";
} else if ($y % 100 == 0) {
    echo $y . " is not the leap year.\n";
} else if ($y % 4 == 0) {
    echo $y . " is the leap year.\n";
} else {
    echo $y . " is not the leap year.\n";
}

?>

 

Output:

1997 is not the leap year.

 

2. PHP program to check leap year using the switch case statement:

<?php
// PHP program to check leap year
// using the switch case statement

$y = 2004;

$r = $y % 400 == 0 || $y % 100 == 0 || $y % 4 == 0;

switch ($r) {
    case 1:
        echo $y . " is the leap year.\n";
        break;

    case 0:
        echo $y . " is not the leap year.\n";
        break;

    default:
        echo $y . " is not the leap year.\n";
}

?>

 

Output:

2004 is the leap year.

 

Tags:

# write a PHP program to find leap year using logical operator

# write a program to check leap year using the function in PHP

# write a PHP program to find leap year using conditional operator

 

Related Articles

How to print a star pattern without using loop in the php programming language Write a program to draw the half pyramid pattern in php language of stars using the for loop How to print the rhombus pattern in the php language of the stars using the for loop Write a program to print the left & right arrow pattern in php language Write a php program to print the butterfly pattern of the numbers by using the for loop How to print the hollow diamond pattern in php language Write a program to print the pascal triangle pattern in php language Write a program to print Floyd's triangle number pattern in php language Write a php program to draw a rectangle using for loop Write a program to print the matrix pattern in php language using the for loop Write a PHP program to check whether a character is an alphabet or not by using the if-else statement and using the conditional operator PHP program to check leap year using the if-else and by using the switch case statement Write a program to find quotient and remainder in php language PHP program to find GCD of two numbers using the while loop and using the for loop Write a php program to find factors of a number using while loop & for loop How to swap the two integers or real numbers without using the third variable in the php language Write a PHP program to find the roots of a quadratic equation by using the sqrt() function & using the if-else condition PHP program to find LCM of two numbers using for loop and with GCD calculation PHP program to calculate the power of N number using for loop and by using pow function PHP program to multiply two same dimension matrices by using the for loop PHP program to find the Normal & Trace of a square matrix by using the for loop PHP program to print prime numbers from 1 to N using for loop PHP program to find the largest and smallest element in an array by using for loop PHP program to print the multiplication table of any integer number with multiplication range PHP program to check input number is even or odd using if-else statement and with conditional operator PHP program to reverse a string by using the for loop PHP program to find sum of digits of a number using while loop of any integer number PHP program to check palindrome number using while loop or not using function of any number PHP program to generate the fibonacci series using iteration of the for loop PHP program to find the factorial of a number using for loop PHP program to check the input character is a vowel or consonant character PHP program of decision making by using the switch case statement PHP program of decision making by using if & if-else statement What are the best PHP frameworks in 2021 to learn? PHP program to enter the P, T, R, and calculate its Compound Interest PHP program to enter the P, T, R, and calculate its Simple Interest PHP program to enter the marks of five subjects and calculate total, average, and percentage PHP program to calculate the area of an equilateral triangle PHP program to enter the base and height of a triangle and find its area PHP program to enter the two angles of a triangle and find the third angle PHP program to enter any number and calculate its square root PHP program to find the power of any number x^y PHP program to convert the days into years, weeks, and days PHP program to enter the temperature in Fahrenheit and convert it to Celsius PHP program to enter the temperature in Celsius and convert it into Fahrenheit PHP program to enter the length in centimeter and convert it into meter and kilometer PHP program to enter the radius of a circle and find its diameter, circumference, and area PHP program to enter the length and breadth of a rectangle and find its area PHP program to enter length and breadth of a rectangle and find its perimeter PHP program to enter two numbers and perform all arithmetic operations
Recent Articles
  • Write a program to find all the patterns of 0(1+)0 in the given string
  • C# program to enter two numbers and find their sum
  • Write a c++ program to store information of a student using the structure with the for loop
  • Write a c program to store information of a student using the structure with the for loop
  • How to write a c++ program to find the sum of natural numbers using recursion
  • How to write a c program to find the sum of natural numbers using recursion
  • Write a python program to convert an array into zig-zag fashion using the function
  • C program to perform input/output of all basic data types
  • Write a python program to print a hollow square star pattern with diagonal using loops (for and while loop)
  • Write a c program to make a circular rotation of an array by k positions using the loops
View All Articles
  W3Codeworld

Get the latest updates

  • ABOUT US
  • About Company
  • Contact Us
  • Terms Conditions
  • Privacy Policy
  • Top Tutorials
  • PHP
  • Codeigniter
  • Laravel
  • Top Articles
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • PHP

© Copyright 2020-2021. All Rights Reserved.