Content · Programming · PHP

PHP cal_info() Function: Usage and Examples

Learn how PHP cal_info works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Returns calendar names and month information for supported calendars.

What Is cal_info() in PHP?

Returns calendar names and month information for supported calendars.

Its syntax is:

cal_info(int $calendar = -1): array

Parameters:

  • $calendar — Accepted as int; optional default -1.

Return type: array. The result structure differs when requesting all calendars rather than one.

Availability: Requires the calendar extension.

Example 1: Basic Usage

<?php

print_r(cal_info(CAL_GREGORIAN)["months"]);

Output:

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
)

The result structure differs when requesting all calendars rather than one.

Example 2: A Different Input

<?php

echo cal_info(CAL_JULIAN)["calname"];

Output:

Julian

The result structure differs when requesting all calendars rather than one.

Practical Example: Applying It in a Program

<?php

$calendarInfo = cal_info(CAL_GREGORIAN); echo $calendarInfo["calname"] . ": " . count($calendarInfo["months"]);

Output:

Gregorian: 12

The result structure differs when requesting all calendars rather than one.

Important Behavior and Edge Cases

  • Key behavior: The result structure differs when requesting all calendars rather than one.
  • Environment: Requires the calendar extension.

Comparison With Related Functions

FunctionPurpose
cal_info()Returns calendar names and month information for supported calendars.
cal_days_in_month()cal_days_in_month() returns a month length; cal_info() describes supported calendars and month names.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: The result structure differs when requesting all calendars rather than oneThe result structure differs when requesting all calendars rather than one.

Key Takeaways

  • Returns calendar names and month information for supported calendars.
  • The result structure differs when requesting all calendars rather than one.
  • Requires the calendar extension.

Summary: The result structure differs when requesting all calendars rather than one.

Share this resourceSend this page to someone who may find it useful.