cal_info() returns names, month data and related information for a selected calendar.
$info = cal_info(CAL_GREGORIAN);
echo $info['calname'];cal_info($calendar);
Here cal_int is an integer to identify the type of calendar required. Here are the values
0 : CAL_GREGORIAN ( Gregorian Calendar )
1 : CAL_JULIAN ( Julian Calendar )
2 : CAL_JEWISH ( Jewish Calendar )
3 : CAL_FRENCH ( French Revolutionary Calendar )
Here is an example of displaying information about the Julian calendar. Use the named constant instead of the numeric calendar ID.
$a = cal_info(CAL_JULIAN);
foreach($a as $key => $val) {
echo "$key -> $val <br>";
foreach($val as $key1 => $val1) {
echo "$key1 -> $val1 <br>";
}
}
The Output is here
months -> Array
1 -> January
2 -> February
3 -> March
4 -> April
5 -> May
6 -> June
7 -> July
8 -> August
9 -> September
10 -> October
11 -> November
12 -> December
abbrevmonths -> Array
1 -> Jan
2 -> Feb
3 -> Mar
4 -> Apr
5 -> May
6 -> Jun
7 -> Jul
8 -> Aug
9 -> Sep
10 -> Oct
11 -> Nov
12 -> Dec
maxdaysinmonth -> 31
calname -> Julian
calsymbol -> CAL_JULIAN
Calling cal_info() without a calendar argument returns information for all supported calendars. Use nested foreach loops; the old each() function was removed from PHP.
$calendars = cal_info();
foreach ($calendars as $calendarId => $calendar) {
echo $calendar['calname'] . "<br>";
foreach ($calendar['months'] as $number => $month) {
echo $number . ' - ' . $month . "<br>";
}
}
DEMO of cal_info() is displayed
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.