Reputation: 75
I need to get all countries with geonames api. I can use $geonames->genomes[2]->countryName
to get country name of 2nd. But I want it auto like while()
how can I use it with while()
in php?
JSON IS HERE
{"geonames":[{"countryName":"Andorra","currencyCode":"EUR","fipsCode":"AN","countryCode":"AD","isoNumeric":"020","north":42.65604389629997,"capital":"Andorra la Vella","continentName":"Europe","areaInSqKm":"468.0","languages":"ca","isoAlpha3":"AND","continent":"EU","south":42.42849259876837,"east":1.7865427778319827,"geonameId":3041565,"west":1.4071867141112762,"population":"84000"},{"countryName":"United Arab Emirates","currencyCode":"AED","fipsCode":"AE","countryCode":"AE","isoNumeric":"784","north":26.08415985107422,"capital":"Abu Dhabi","continentName":"Asia","areaInSqKm":"82880.0","languages":"ar-AE,fa,en,hi,ur","isoAlpha3":"ARE","continent":"AS","south":22.633329391479492,"east":56.38166046142578,"geonameId":290557,"west":51.58332824707031,"population":"4975593"}]}
Upvotes: 2
Views: 982
Reputation: 2287
We have a CSV file that has all the countries in the world, their corresponding ISO codes, and their short and formal names in English, French, Spanish, Russian, Chinese, Arabic, and Italian. This was compiled from various government and international references:
http://www.opengeocode.org/download/countrynames.txt
References are cited at:
http://www.opengeocode.org/download.php#countrynames
Upvotes: 1
Reputation: 976
You can use a for loop:
for ($i = 0; $i < $numCountries; $i++) {
echo $geonames->geonames[$i]->countryName;
}
Upvotes: 0