当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP cal_info( )用法及代码示例


PHP中的cal_info()函数是一个内置函数,用于返回有关指定日历的信息。 cal_info()函数返回一个数组,该数组包含calname,month,abbrevmonth和maxdaysinmonth和calsymbol。
它以日历为参数,并返回与指定日历有关的信息。

用法:

cal_info($calendar)

参数:PHP中的cal_info()函数仅接受一个参数$calender。此参数指定一个数字,该数字指示您要了解的日历。以下是可用作此参数值的有效数字列表。


  • 0 = CAL_GREGORIAN
  • 1 = CAL_JULIAN
  • 2 = CAL_JEWISH
  • 3 = CAL_FRENCH

返回值:它返回有关指定日历的信息。

错误与异常

  1. 如果在参数中未指定日历,则cal_info()函数将返回有关所有日历的信息。
  2. 要将日历指定为cal_info()函数的参数,需要提及其各自的数值而不是日历名称,例如格里高利历的“0”。

以下示例程序旨在说明cal_info()函数。

程序1:

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

输出:

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
)

程序2:

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

输出:

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
)

参考:
http://php.net/manual/en/function.cal-info.php



相关用法


注:本文由纯净天空筛选整理自Shubrodeep Banerjee大神的英文原创作品 PHP | cal_info() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。