PHP code example of datingvip / php-rest-countries

1. Go to this page and download the library: Download datingvip/php-rest-countries 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/ */

    

datingvip / php-rest-countries example snippets


use NNV\RestCountries;

$restCountries = new RestCountries;

$restCountries->all();

$restCountries->byName("viet");

// or with full name
$restCountries->byName("vietnam", true);

// Single country code
$restCountries->byCodes("vn");

// Multiple country codes
$restCountries->byCodes(["vn", "cn", "th"]);

$restCountries->byCurrency("vnd");

$restCountries->byLanguage("vi");

$restCountries->byCapitalCity("hanoi");

$restCountries->byCallingCode("84");

$restCountries->byRegion("asia");

$restCountries->byRegionalBloc("asean");

// You can use `fields([])` with any available methods

$restCountries->fields(["name", "callingCodes", "capital"])->all();

$restCountries->fields(["name"])->byName("vietnam", true);

$restCountries->fields(["callingCodes"])->byRegionalBloc("asean");