Tutorialspoint.dev

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:

<?php
  
// displaying information
// regarding gregorian calendar
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
  
// displaying information
// regarding jewish calendar
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



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter