PHP code example of rapidwebltd / php-countries
1. Go to this page and download the library: Download rapidwebltd/php-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/ */
rapidwebltd / php-countries example snippets
use RapidWeb\Countries\Countries;
$countries = new Countries;
foreach($countries->all() as $country) {
var_dump($country->name.' - '.$country->officialName);
}
var_dump($countries->getByName('United Kingdom'));
/*
object(RapidWeb\Countries\Country)#4869 (16) {
["name"]=>
string(14) "United Kingdom"
["officialName"]=>
string(52) "United Kingdom of Great Britain and Northern Ireland"
["topLevelDomains"]=>
array(1) {
[0]=>
string(3) ".uk"
}
["isoCodeAlpha2"]=>
string(2) "GB"
["isoCodeAlpha3"]=>
string(3) "GBR"
["isoCodeNumeric"]=>
string(3) "826"
["languages"]=>
array(1) {
[0]=>
string(7) "English"
}
["languageCodes"]=>
array(1) {
[0]=>
string(3) "eng"
}
["currencyCodes"]=>
array(1) {
[0]=>
string(3) "GBP"
}
["callingCodes"]=>
array(1) {
[0]=>
string(2) "44"
}
["capital"]=>
string(6) "London"
["region"]=>
string(6) "Europe"
["subregion"]=>
string(15) "Northern Europe"
["latitude"]=>
int(54)
["longitude"]=>
int(-2)
["areaInKilometres"]=>
int(242900)
}
*/
var_dump($countries->getByIsoCode('USA'));
/*
object(RapidWeb\Countries\Country)#4693 (16) {
["name"]=>
string(13) "United States"
["officialName"]=>
string(24) "United States of America"
// etc...
}
*/
var_dump($countries->getByLanguage('German'));
/*
array(5) {
[0]=>
object(RapidWeb\Countries\Country)#4913 (16) {
["name"]=>
string(7) "Belgium"
["officialName"]=>
// etc...
}
[1]=>
object(RapidWeb\Countries\Country)#4883 (16) {
["name"]=>
string(7) "Germany"
["officialName"]=>
string(27) "Federal Republic of Germany"
// etc...
}
[2]=>
object(RapidWeb\Countries\Country)#4826 (16) {
["name"]=>
string(13) "Liechtenstein"
["officialName"]=>
string(29) "Principality of Liechtenstein"
// etc...
}
[3]=>
object(RapidWeb\Countries\Country)#4808 (16) {
["name"]=>
string(10) "Luxembourg"
["officialName"]=>
string(25) "Grand Duchy of Luxembourg"
// etc...
}
[4]=>
object(RapidWeb\Countries\Country)#4871 (16) {
["name"]=>
string(7) "Namibia"
["officialName"]=>
string(19) "Republic of Namibia"
// etc...
}
}
*/
composer