當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。