PHP code example of jabarihunt / country-codes

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

    

jabarihunt / country-codes example snippets




 use jabarihunt/CountryCodes;

public const CountryCodes::CODE_TYPE_COUNTRY_NAME
public const CountryCodes::CODE_TYPE_NATIVE_NAME
public const CountryCodes::CODE_TYPE_2_LETTER
public const CountryCodes::CODE_TYPE_3_LETTER
public const CountryCodes::CODE_TYPE_UN



    $countryName     = 'Haiti';
    $countryCodeType = CountryCodes::CODE_TYPE_COUNTRY_NAME;
    $countryCodes    = CountryCodes::get($countryCodeType, $countryName);
    
    var_dump($countryCodes);




    $unitedNationsCode = '332';
    $countryCodeType   = CountryCodes::CODE_TYPE_UN;
    $countryCodes      = CountryCodes::get($countryCodeType, $unitedNationsCode);




    // RETURN HARD CODED CLASS VALUES
    $allCountryCodes = CountryCodes::getAll(); 
    
    /* OR */

    // RETURN DATA VIA HTTP REQUEST TO THE REST COUNTRIES API 
    $allCountryCodes = CountryCodes::getAll(TRUE);