Wednesday, November 20, 2024
Google search engine
HomeLanguagesPHP | IntlCalendar isSet() Function

PHP | IntlCalendar isSet() Function

The IntlCalendar::isSet() function is an inbuilt function in PHP which is used to check whether a given field is set or not. This function is opposite to IntlCalendar::clear() function.

Syntax:

  • Object oriented style
    bool IntlCalendar::isSet( int $field )
  • Procedural style
    bool intlcal_is_set( IntlCalendar $cal, int $field )

Parameters: This function uses two parameters as mentioned above and described below:

  • $cal: This parameter holds the resource of IntlCalendar object.
  • $field: This parameter holds one of the IntlCalendar date/time field constants. The value of field constants are integer and lies between 0 to IntlCalendar::FIELD_COUNT.

Return Value: This function returns TRUE if the field is set and returns error if the field is not set.

Below program illustrates the IntlCalendar::isSet() function in PHP:

Program:




<?php
  
// Set the DateTime zone
ini_set('date.timezone', 'Asia/Calcutta');
  
// Create an instance of IntlCalendar
$calendar = IntlCalendar::createInstance('Asia/Calcutta');
  
// Check month field is set or not
var_dump($calendar->isSet(IntlCalendar::FIELD_MONTH));
  
// Set the DateTime to the object
$calendar->set(2019, 8, 29);
  
// Check for month field
var_dump($calendar->isSet(IntlCalendar::FIELD_MONTH));
  
// Set the DateTime object
$calendar->set(strtotime('2019-09-22 12:30:00'));
  
// Check for year field
var_dump($calendar->isSet(IntlCalendar::FIELD_YEAR));
  
?>


Output:

bool(true)
bool(true)
bool(true)

Reference: https://www.php.net/manual/en/intlcalendar.isset.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments