Home > Article > Backend Development > Correct use of easter_days() function in PHP
PHP
There are many functions related to date. Some of them are special functions that are not commonly used, but they need to be used in some special cases, such as You need to specify the number of days between March 21st and Easter of the year. In this case, you need the easter_days()
function. This article will take you to take a look.
First let’s take a look at the syntax of the easter_days()
function
easter_days ( int $year = ? , int $method = CAL_EASTER_DEFAULT )
$year: year in positive form, if no year is specified , the default is the current year.
$method: When set to CAL_EASTER_ROMAN, the Gregorian calendar can be used to calculate the Easter date between 1582-1752
Return value: Returns the number of days from March 21st to Easter based on the given parameter year.
Code example:
1. Parameterless form
<?php echo easter_days(); echo "<br>";
输出:14
2. Parameterized form
<?php echo easter_days(2022); echo "<br>"; echo easter_days(2021); echo "<br>"; echo easter_days(1999); echo "<br>"; echo easter_days(1492); echo "<br>"; echo easter_days(1913); ?>
输出:27 14 14 32 2
Recommendation: 《2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of Correct use of easter_days() function in PHP. For more information, please follow other related articles on the PHP Chinese website!