PHP code example of countlang / countlang

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

    

countlang / countlang example snippets


// include composer autoloader if you haven't done it yet
/ initialize CountLand interface
$countLang = new CountLang();

// get a collection with all countries 
$allCountries = $countlang->getCountries();
// get a list of all official country names 
$allCountryNames = $allCountries->select('officialName');

// get the country entity of Denmark
$denmark = $countlang->getCountry('Denmark');

// get a collection of countries that share common border with Denmark
$denmarkNeigbors = $denmark->getBordersCollection();

// get a collection with all languages of Denmark
$denmarkLanguages = $denmark->getLanguagesCollection();
// get usage percentage of Danish language in Denmark
$usagePercentageOfDanishLanguageInDenmark = $denmarkLanguages->findEntity('Danish')->getUsagePercentage();

// get first currency entity from collection of Denmark's currencies
$denmarkCurrency = $denmark->getCurrenciesCollection()->getEntity();

// get name of Denmark's sub-region
$denmarkSubRegion = $denmark->getSubRegionEntity()->getName();

// get code of region Denmark is belong to
$denmarkRegion = $denmark->getRegionEntity()->getCode();

// get a collection of all languages 
$allLanguages = $countlang->getLanguages();
// get a list of alpha 3T codes (according to ISO 639) for all languages 
$allLanguagesCodes = $allLanguages->select('alpha3TCode');

// get the language entity of Danish
$danishLanguage = $countlang->getLanguage('Danish');

// get a collection with all Danish-speaking countries entities
$danishLanguageCountries = $danishLanguage->getCountriesCollection();
// get a collection with all Danish-speaking countries 
// that have a population more than half a million people
$mostPopulatedDanishLanguageCountries = $danishLanguageCountries->filter('population', 500000, 'gt');
// get a collection with all Danish-speaking countries 
// that have a population less than 100 thousand people
// and have access to the world's ocean
$filteredDanishLanguageCountries = $danishLanguageCountries->multiFilter([
    ['population', 100000, CountLang\Filter\Filter::OPERATOR_LT],
    ['isLandLocked', false],
]);

// get a collection of all currencies 
$allCurrencies = $countlang->getCurrencies();
// get an associative array with official names and symbols of all countries
$allCurrenciesNamesAndSymbols = $allCurrencies->select(['officialName', 'symbol']);

// get the currency entity of Danish Krone
$danishKrona = $countlang->getCurrency('Danish Krone');

// get a collection of all countries that use Danish Krone
$danishKronaCountries = $danishKrona->getCountriesCollection();

// get a collection of all regions 
$allRegions = $countlang->getRegions();
// print the collection (in JSON format)
// Note: when used as a string, collection or entity will be converted to JSON
echo $allRegions;

// get the region entity of Europe
$europe = $countlang->getRegion('Europe');

// get a collection of European countries
$europeanCountries = $europe->getCountriesCollection();

// get a collection of Europe sub-regions
$subRegions = $europe->getSubRegionsCollection();

// get a collection of all sub-regions 
$allSubRegions = $countlang->getSubRegions();
// get an associative array with complete data for all sub-regions 
$allSubRegionsData = $allSubRegions->select();

// get the region entity of Northern Europe
$northernEurope = $countlang->getSubRegion('Northern Europe');

// get the region entity of Europe
$europe = $northernEurope->getRegionEntity();

// get the number of countries in the Northern Europe sub-region
$northernEuropeanCountriesAmount = $northernEurope->getCountriesCollection()->count();