PHP code example of holidayapi / holidayapi-php

1. Go to this page and download the library: Download holidayapi/holidayapi-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

holidayapi / holidayapi-php example snippets



$key = 'Insert your API key here';
$holiday_api = new \HolidayAPI\Client(['key' => $key]);

try {
    // Fetch supported countries and subdivisions
    $countries = $holiday_api->countries();

    // Fetch supported languages
    $languages = $holiday_api->languages();

    // Fetch holidays with minimum parameters
    $holidays = $holiday_api->holidays([
      'country' => 'US',
      'year' => 2019,
    ]);

    var_dump($countries, $languages, $holidays);
} catch (Exception $e) {
    var_dump($e);
}


$holiday_api->countries();


$holiday_api->countries([
  'public' => true,
]);


$holiday_api->countries([
  'country' => 'NO',
]);


$holiday_api->countries([
  'search' => 'united',
]);


$holiday_api->languages();


$holiday_api->languages([
  'language' => 'es',
]);


$holiday_api->languages([
  'search' => 'Chinese',
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'month' => 7,
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'month' => 7,
  'day' => 4,
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'month' => 7,
  'day' => 4,
  'upcoming' => true,
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'month' => 7,
  'day' => 4,
  'previous' => true,
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'public' => true,
]);


$holiday_api->holidays([
  'country' => 'GB-ENG',
  'year' => 2019,
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'subdivisions' => true,
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'search' => 'New Year',
]);


$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'language' => 'zh', // Chinese (Simplified)
]);


$holiday_api->holidays([
  'country' => 'US,GB,NZ',
  'year' => 2019,
]);

$holiday_api->holidays([
  'country' => ['US', 'GB', 'NZ'],
  'year' => 2019,
]);


$holiday_api->workday([
  'country' => 'US',
  'start' => '2019-07-01',
  'days' => 7,
]);


$holiday_api->workdays([
  'country' => 'US',
  'start' => '2019-07-01',
  'end' => '2019-07-10',
]);
shell
composer