Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP program to check if a year is leap year or not
To check if a year is leap year or not in PHP, the code is as follows −
Example
<?php
function year_check($my_year){
if ($my_year % 400 == 0)
print("It is a leap year");
else if ($my_year % 100 == 0)
print("It is not a leap year");
else if ($my_year % 4 == 0)
print("It is a leap year");
else
print("It is not a leap year");
}
$my_year = 1900;
year_check($my_year);
?>
Output
It is not a leap year
A function named ‘year_check’ is defined that takes a year as a parameter. It checks to see if the year can be divided by 400 or 4 completely, if yes, it means it is a leap year. Otherwise, it is a leap year. The value for year is defined outside the function, and the function is called by passing this year as a parameter to it. Relevant output is displayed on the console.
Advertisements