PHP | cal_info( ) Function

The cal_info() function in PHP is an inbuilt function which is used to return information about a specified calendar. The cal_info() function returns an array which 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 $calender. This parameter specifies a number which 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 Exception:

  1. If no calendar is specified in the parameters, the cal_info() function returns information about all the calendars.
  2. 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// displaying information
// regarding gregorian calendar
print_r (cal_info(0));
  
?>

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// displaying information
// regarding jewish calendar
print_r (cal_info(2));
  
?>

chevron_right


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



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.