PHP code example of tiny-blocks / country

1. Go to this page and download the library: Download tiny-blocks/country 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/ */

    

tiny-blocks / country example snippets


use TinyBlocks\Country\Alpha2Code;

$alpha2Code = Alpha2Code::UNITED_STATES_OF_AMERICA;

$alpha2Code->name;              # UNITED_STATES_OF_AMERICA
$alpha2Code->value;             # US
$alpha2Code->toAlpha3()->value; # USA

use TinyBlocks\Country\Alpha3Code;

$alpha3Code = Alpha3Code::UNITED_STATES_OF_AMERICA;

$alpha3Code->name;              # UNITED_STATES_OF_AMERICA
$alpha3Code->value;             # USA
$alpha3Code->toAlpha2()->value; # US

use TinyBlocks\Country\Country;
use TinyBlocks\Country\Alpha2Code;

$country = Country::from(alphaCode: Alpha2Code::UNITED_STATES_OF_AMERICA);

$country->name;          # United States of America
$country->alpha2->value; # US
$country->alpha3->value; # USA

use TinyBlocks\Country\Country;
use TinyBlocks\Country\Alpha3Code;

$country = Country::from(alphaCode: Alpha3Code::UNITED_STATES_OF_AMERICA);

$country->name;          # United States of America
$country->alpha2->value; # US
$country->alpha3->value; # USA

use TinyBlocks\Country\Country;
use TinyBlocks\Country\Alpha3Code;

$country = Country::from(alphaCode: Alpha3Code::UNITED_STATES_OF_AMERICA, name: 'United States');

$country->name;          # United States
$country->alpha2->value; # US
$country->alpha3->value; # USA

use TinyBlocks\Country\Country;

$country = Country::fromString(alphaCode: 'US');

$country->name;          # United States of America
$country->alpha2->value; # US
$country->alpha3->value; # USA

use TinyBlocks\Country\Country;

$country = Country::fromString(alphaCode: 'USA', name: 'United States');

$country->name;          # United States
$country->alpha2->value; # US
$country->alpha3->value; # USA

use TinyBlocks\Country\Country;
use TinyBlocks\Country\Alpha2Code;

$country = Country::from(alphaCode: Alpha2Code::BRAZIL);

$country->timezones->count();      # 4
$country->timezones->default();    # Timezone("America/Noronha")
$country->timezones->toStrings();  # ["America/Noronha", "America/Belem", "America/Sao_Paulo", ...]

use TinyBlocks\Country\Country;
use TinyBlocks\Country\Alpha2Code;

$country = Country::from(alphaCode: Alpha2Code::BRAZIL);

$country->timezones->all(); # [Timezone("America/Noronha"), Timezone("America/Belem"), ...]

use TinyBlocks\Country\Country;
use TinyBlocks\Country\Alpha2Code;

$country = Country::from(alphaCode: Alpha2Code::JAPAN);
$country->timezones->default(); # Timezone("Asia/Tokyo")

$country = Country::from(alphaCode: Alpha2Code::BOUVET_ISLAND);
$country->timezones->default(); # Timezone("UTC")

use TinyBlocks\Country\Country;
use TinyBlocks\Country\Alpha2Code;

$country = Country::from(alphaCode: Alpha2Code::UNITED_STATES_OF_AMERICA);

$country->timezones->findByIdentifierOrUtc(iana: 'America/New_York'); # Timezone("America/New_York")
$country->timezones->findByIdentifierOrUtc(iana: 'Asia/Tokyo');       # Timezone("UTC")

use TinyBlocks\Country\Country;
use TinyBlocks\Country\Alpha2Code;

$country = Country::from(alphaCode: Alpha2Code::JAPAN);

$country->timezones->contains(iana: 'Asia/Tokyo');       # true
$country->timezones->contains(iana: 'America/New_York'); # false