The easter_days() Function is a built-in function in PHP which returns the number of days after March 21, that the Easter Day is in the given year. When no year is given, the current year is taken as the default value.
Syntax:
php
Output:
php
Output:
php
Output:
easter_days( $year, $method )Parameters: The function accepts two optional parameters as shown above and explained below:
- $year This parameter specifies the year. When no parameter is passed the current year is taken as the default value.
- $method - This parameter allows you to calculate easter dates based on other calendars. If the $method is set to CAL_EASTER_ROMAN, it uses the Gregorian calendar during the years 1582 - 1752.
Input : $year = 2018 Output : 11 Input : $year = 2017 Output : 26 Input: $year = 2015 $method = CAL_EASTER_ROMAN Output : 15Below programs illustrates the use of easter_days() function: Program 1: The program below explains the working of easter_days() function when no parameter is passed.
<?php
// PHP program to demonstrate the
// easter_days() function
// when no parameter is passed
echo easter_days(), "\n";
// verified by passing current year
$year = 2018;
echo easter_days($year);
?>
11 11Program 2: The program below explains the working of easter_days() function when $year parameter is passed
<?php
// PHP program to demonstrate the
// easter_days() function
// when $year parameter is passed
$year = 2015;
// no of days for Easter after march 21 of year 2015
echo easter_days($year), "\n";
// the Easter date of year 2015
echo date("M-d-Y", easter_date($year));
?>
15 Apr-05-2015Program 3: The program below explains the working of easter_days() function when both the parameters is passed.
<?php
// PHP program to demonstrate the
// easter_days() function
// when both parameters are passed
$year = 2014;
// no of days for Easter after march 21 of year 2014
// of Gregorian Calendar
echo easter_days($year, CAL_EASTER_ROMAN), "\n";
?>
30Reference: https://www.php.net/manual/en/function.easter-days.php