PHP | cal_info( ) Function
The cal_info() function in PHP is an inbuilt function that is used to return information about a specified calendar. The cal_info() function returns an array that contains the calname, month, abbrevmonth and maxdaysinmonth, and calsymbol.
It takes the calendar as a parameter and returns the information respective to the specified calendar.
Syntax:
cal_info($calendar)
Parameters: The cal_info() function in PHP accepts only one parameter $calendar. This parameter specifies a number that indicates the calendar you want to know about. Below is the list of valid numbers which can be used as value for this parameter.
- 0 = CAL_GREGORIAN
- 1 = CAL_JULIAN
- 2 = CAL_JEWISH
- 3 = CAL_FRENCH
Return Value: It returns information about a specified calendar.
Errors And Exceptions:
- If no calendar is specified in the parameters, the cal_info() function returns information about all the calendars.
- To specify a calendar as a parameter for the cal_info() function, one needs to mention its respective numerical value instead of the calendar name such as “0” for Gregorian calendar.
Below programs illustrate the cal_info() function.
Program 1:
PHP
<?php
print_r (cal_info(0));
?>
|
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] => Gregorian
[calsymbol] => CAL_GREGORIAN
)
Program 2:
PHP
<?php
print_r (cal_info(2));
?>
|
Output:
Array
(
[months] => Array
(
[1] => Tishri
[2] => Heshvan
[3] => Kislev
[4] => Tevet
[5] => Shevat
[6] => Adar I
[7] => Adar II
[8] => Nisan
[9] => Iyyar
[10] => Sivan
[11] => Tammuz
[12] => Av
[13] => Elul
)
[abbrevmonths] => Array
(
[1] => Tishri
[2] => Heshvan
[3] => Kislev
[4] => Tevet
[5] => Shevat
[6] => Adar I
[7] => Adar II
[8] => Nisan
[9] => Iyyar
[10] => Sivan
[11] => Tammuz
[12] => Av
[13] => Elul
)
[maxdaysinmonth] => 30
[calname] => Jewish
[calsymbol] => CAL_JEWISH
)
Reference:
http://php.net/manual/en/function.cal-info.php
Last Updated :
29 Sep, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...