PHP如何使用cal_info()函数?用法示例

2021年3月28日11:58:41 发表评论 239 次浏览

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

它以日历为参数, 并返回与指定日历有关的信息。

语法如下:

cal_info($calendar)

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

  • 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


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: