PHP - Calendar cal_info() Function
The PHP Calendar cal_info() function is used to return an array that contains information about a given calendar. The array contains the following elements: calname, calsymbol, month, abbrevmonth and maxdaysinmonth.
Syntax
Below is the syntax of the PHP Calendar cal_info() function −
array cal_info(int $calendar = -1)
Parameters
This function accepts $calendar (Optional) parameter which is an integer value showing the calendar ID. If not specified or set to -1, it will return information about all available calendars.
The following calendar values can be used −
- 0 = CAL_GREGORIAN
- 1 = CAL_JULIAN
- 2 = CAL_JEWISH
- 3 = CAL_FRENCH
Return Value
The cal_info() function returns an array containing information on the given calendar, or all calendars if no specific ID is given.
PHP Version
First introduced in core PHP 4.1.0, the cal_info() function continues to function easily in PHP 5, PHP 7, and PHP 8.
Example 1
First we will show you the basic example of the PHP Calendar cal_info() function to get the information about the calendar. Here we have given 0 as the value for $calendar parameter.
<?php // Call the cal_info function $info = cal_info(0); // Here CAL_GREGORIAN can be used at the place of 0 // Display the result print_r($info); ?>
Output
Here is the outcome of the following code −
Array (
[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]=> Gregorian
[calsymbol]=> CAL_GREGORIAN
)
Example 2
This PHP example uses the cal_info() method with CAL_JULIAN value to retrieve and show Julian calendar information.
<?php // Call the cal_info function $info = cal_info(CAL_JULIAN); // Display the result print_r($info); ?>
Output
This will generate the below output −
Array
(
[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
)
Example 3
This example demonstrates how you can retrieve and display information about the French calendar using cal_info() and CAL_FRENCH.
<?php // Call the cal_info function $info = cal_info(CAL_FRENCH); // CAL_FRENCH to get the french calendar information // Display the result print_r($info); ?>
Output
This will create the below output −
Array
(
[months] => Array
(
[1] => Vendemiaire
[2] => Brumaire
[3] => Frimaire
[4] => Nivose
[5] => Pluviose
[6] => Ventose
[7] => Germinal
[8] => Floreal
[9] => Prairial
[10] => Messidor
[11] => Thermidor
[12] => Fructidor
[13] => Extra
)
[abbrevmonths] => Array
(
[1] => Vendemiaire
[2] => Brumaire
[3] => Frimaire
[4] => Nivose
[5] => Pluviose
[6] => Ventose
[7] => Germinal
[8] => Floreal
[9] => Prairial
[10] => Messidor
[11] => Thermidor
[12] => Fructidor
[13] => Extra
)
[maxdaysinmonth] => 30
[calname] => French
[calsymbol] => CAL_FRENCH
)