Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP array of all country names
<?php
$countries = array("Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "France Metropolitan", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and Mc Donald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao, People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, The Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia (Slovak Republic)", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "St. Helena", "St. Pierre and Miquelon", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe");
?>
@theenoahmason
Copy link

theenoahmason commented Feb 19, 2018

Thanks for the info @slaFFik, Fixed my example above. Any others you can see off hand?

@imchaitanyadesai
Copy link

imchaitanyadesai commented Mar 14, 2018

Thank you for this.

@DDiimmkkaass
Copy link

DDiimmkkaass commented Apr 14, 2018

thanks a lot

@quangpro1610
Copy link

quangpro1610 commented Jun 7, 2018

Thanks you for your help :)

@bucktechnologies
Copy link

bucktechnologies commented Oct 26, 2018

i want a country list with code , country name and continent
eg. $country_array = array( "US" => "United States"=>"North America")

@owldesign
Copy link

owldesign commented Nov 19, 2018

public $countries = [
        "AF" => ["country" => "Afghanistan", "continent" => "Asia"],
        "AX" => ["country" => "Åland Islands", "continent" => "Europe"],
        "AL" => ["country" => "Albania", "continent" => "Europe"],
        "DZ" => ["country" => "Algeria", "continent" => "Africa"],
        "AS" => ["country" => "American Samoa", "continent" => "Oceania"],
        "AD" => ["country" => "Andorra", "continent" => "Europe"],
        "AO" => ["country" => "Angola", "continent" => "Africa"],
        "AI" => ["country" => "Anguilla", "continent" => "North America"],
        "AQ" => ["country" => "Antarctica", "continent" => "Antarctica"],
        "AG" => ["country" => "Antigua and Barbuda", "continent" => "North America"],
        "AR" => ["country" => "Argentina", "continent" => "South America"],
        "AM" => ["country" => "Armenia", "continent" => "Asia"],
        "AW" => ["country" => "Aruba", "continent" => "North America"],
        "AU" => ["country" => "Australia", "continent" => "Oceania"],
        "AT" => ["country" => "Austria", "continent" => "Europe"],
        "AZ" => ["country" => "Azerbaijan", "continent" => "Asia"],
        "BS" => ["country" => "Bahamas", "continent" => "North America"],
        "BH" => ["country" => "Bahrain", "continent" => "Asia"],
        "BD" => ["country" => "Bangladesh", "continent" => "Asia"],
        "BB" => ["country" => "Barbados", "continent" => "North America"],
        "BY" => ["country" => "Belarus", "continent" => "Europe"],
        "BE" => ["country" => "Belgium", "continent" => "Europe"],
        "BZ" => ["country" => "Belize", "continent" => "North America"],
        "BJ" => ["country" => "Benin", "continent" => "Africa"],
        "BM" => ["country" => "Bermuda", "continent" => "North America"],
        "BT" => ["country" => "Bhutan", "continent" => "Asia"],
        "BO" => ["country" => "Bolivia", "continent" => "South America"],
        "BA" => ["country" => "Bosnia and Herzegovina", "continent" => "Europe"],
        "BW" => ["country" => "Botswana", "continent" => "Africa"],
        "BV" => ["country" => "Bouvet Island", "continent" => "Antarctica"],
        "BR" => ["country" => "Brazil", "continent" => "South America"],
        "IO" => ["country" => "British Indian Ocean Territory", "continent" => "Asia"],
        "BN" => ["country" => "Brunei Darussalam", "continent" => "Asia"],
        "BG" => ["country" => "Bulgaria", "continent" => "Europe"],
        "BF" => ["country" => "Burkina Faso", "continent" => "Africa"],
        "BI" => ["country" => "Burundi", "continent" => "Africa"],
        "KH" => ["country" => "Cambodia", "continent" => "Asia"],
        "CM" => ["country" => "Cameroon", "continent" => "Africa"],
        "CA" => ["country" => "Canada", "continent" => "North America"],
        "CV" => ["country" => "Cape Verde", "continent" => "Africa"],
        "KY" => ["country" => "Cayman Islands", "continent" => "North America"],
        "CF" => ["country" => "Central African Republic", "continent" => "Africa"],
        "TD" => ["country" => "Chad", "continent" => "Africa"],
        "CL" => ["country" => "Chile", "continent" => "South America"],
        "CN" => ["country" => "China", "continent" => "Asia"],
        "CX" => ["country" => "Christmas Island", "continent" => "Asia"],
        "CC" => ["country" => "Cocos (Keeling] Islands", "continent" => "Asia"],
        "CO" => ["country" => "Colombia", "continent" => "South America"],
        "KM" => ["country" => "Comoros", "continent" => "Africa"],
        "CG" => ["country" => "Congo", "continent" => "Africa"],
        "CD" => ["country" => "The Democratic Republic of The Congo", "continent" => "Africa"],
        "CK" => ["country" => "Cook Islands", "continent" => "Oceania"],
        "CR" => ["country" => "Costa Rica", "continent" => "North America"],
        "CI" => ["country" => "Cote D'ivoire", "continent" => "Africa"],
        "HR" => ["country" => "Croatia", "continent" => "Europe"],
        "CU" => ["country" => "Cuba", "continent" => "North America"],
        "CY" => ["country" => "Cyprus", "continent" => "Asia"],
        "CZ" => ["country" => "Czech Republic", "continent" => "Europe"],
        "DK" => ["country" => "Denmark", "continent" => "Europe"],
        "DJ" => ["country" => "Djibouti", "continent" => "Africa"],
        "DM" => ["country" => "Dominica", "continent" => "North America"],
        "DO" => ["country" => "Dominican Republic", "continent" => "North America"],
        "EC" => ["country" => "Ecuador", "continent" => "South America"],
        "EG" => ["country" => "Egypt", "continent" => "Africa"],
        "SV" => ["country" => "El Salvador", "continent" => "North America"],
        "GQ" => ["country" => "Equatorial Guinea", "continent" => "Africa"],
        "ER" => ["country" => "Eritrea", "continent" => "Africa"],
        "EE" => ["country" => "Estonia", "continent" => "Europe"],
        "ET" => ["country" => "Ethiopia", "continent" => "Africa"],
        "FK" => ["country" => "Falkland Islands (Malvinas]", "continent" => "South America"],
        "FO" => ["country" => "Faroe Islands", "continent" => "Europe"],
        "FJ" => ["country" => "Fiji", "continent" => "Oceania"],
        "FI" => ["country" => "Finland", "continent" => "Europe"],
        "FR" => ["country" => "France", "continent" => "Europe"],
        "GF" => ["country" => "French Guiana", "continent" => "South America"],
        "PF" => ["country" => "French Polynesia", "continent" => "Oceania"],
        "TF" => ["country" => "French Southern Territories", "continent" => "Antarctica"],
        "GA" => ["country" => "Gabon", "continent" => "Africa"],
        "GM" => ["country" => "Gambia", "continent" => "Africa"],
        "GE" => ["country" => "Georgia", "continent" => "Asia"],
        "DE" => ["country" => "Germany", "continent" => "Europe"],
        "GH" => ["country" => "Ghana", "continent" => "Africa"],
        "GI" => ["country" => "Gibraltar", "continent" => "Europe"],
        "GR" => ["country" => "Greece", "continent" => "Europe"],
        "GL" => ["country" => "Greenland", "continent" => "North America"],
        "GD" => ["country" => "Grenada", "continent" => "North America"],
        "GP" => ["country" => "Guadeloupe", "continent" => "North America"],
        "GU" => ["country" => "Guam", "continent" => "Oceania"],
        "GT" => ["country" => "Guatemala", "continent" => "North America"],
        "GG" => ["country" => "Guernsey", "continent" => "Europe"],
        "GN" => ["country" => "Guinea", "continent" => "Africa"],
        "GW" => ["country" => "Guinea-bissau", "continent" => "Africa"],
        "GY" => ["country" => "Guyana", "continent" => "South America"],
        "HT" => ["country" => "Haiti", "continent" => "North America"],
        "HM" => ["country" => "Heard Island and Mcdonald Islands", "continent" => "Antarctica"],
        "VA" => ["country" => "Holy See (Vatican City State]", "continent" => "Europe"],
        "HN" => ["country" => "Honduras", "continent" => "North America"],
        "HK" => ["country" => "Hong Kong", "continent" => "Asia"],
        "HU" => ["country" => "Hungary", "continent" => "Europe"],
        "IS" => ["country" => "Iceland", "continent" => "Europe"],
        "IN" => ["country" => "India", "continent" => "Asia"],
        "ID" => ["country" => "Indonesia", "continent" => "Asia"],
        "IR" => ["country" => "Iran", "continent" => "Asia"],
        "IQ" => ["country" => "Iraq", "continent" => "Asia"],
        "IE" => ["country" => "Ireland", "continent" => "Europe"],
        "IM" => ["country" => "Isle of Man", "continent" => "Europe"],
        "IL" => ["country" => "Israel", "continent" => "Asia"],
        "IT" => ["country" => "Italy", "continent" => "Europe"],
        "JM" => ["country" => "Jamaica", "continent" => "North America"],
        "JP" => ["country" => "Japan", "continent" => "Asia"],
        "JE" => ["country" => "Jersey", "continent" => "Europe"],
        "JO" => ["country" => "Jordan", "continent" => "Asia"],
        "KZ" => ["country" => "Kazakhstan", "continent" => "Asia"],
        "KE" => ["country" => "Kenya", "continent" => "Africa"],
        "KI" => ["country" => "Kiribati", "continent" => "Oceania"],
        "KP" => ["country" => "Democratic People's Republic of Korea", "continent" => "Asia"],
        "KR" => ["country" => "Republic of Korea", "continent" => "Asia"],
        "KW" => ["country" => "Kuwait", "continent" => "Asia"],
        "KG" => ["country" => "Kyrgyzstan", "continent" => "Asia"],
        "LA" => ["country" => "Lao People's Democratic Republic", "continent" => "Asia"],
        "LV" => ["country" => "Latvia", "continent" => "Europe"],
        "LB" => ["country" => "Lebanon", "continent" => "Asia"],
        "LS" => ["country" => "Lesotho", "continent" => "Africa"],
        "LR" => ["country" => "Liberia", "continent" => "Africa"],
        "LY" => ["country" => "Libya", "continent" => "Africa"],
        "LI" => ["country" => "Liechtenstein", "continent" => "Europe"],
        "LT" => ["country" => "Lithuania", "continent" => "Europe"],
        "LU" => ["country" => "Luxembourg", "continent" => "Europe"],
        "MO" => ["country" => "Macao", "continent" => "Asia"],
        "MK" => ["country" => "Macedonia", "continent" => "Europe"],
        "MG" => ["country" => "Madagascar", "continent" => "Africa"],
        "MW" => ["country" => "Malawi", "continent" => "Africa"],
        "MY" => ["country" => "Malaysia", "continent" => "Asia"],
        "MV" => ["country" => "Maldives", "continent" => "Asia"],
        "ML" => ["country" => "Mali", "continent" => "Africa"],
        "MT" => ["country" => "Malta", "continent" => "Europe"],
        "MH" => ["country" => "Marshall Islands", "continent" => "Oceania"],
        "MQ" => ["country" => "Martinique", "continent" => "North America"],
        "MR" => ["country" => "Mauritania", "continent" => "Africa"],
        "MU" => ["country" => "Mauritius", "continent" => "Africa"],
        "YT" => ["country" => "Mayotte", "continent" => "Africa"],
        "MX" => ["country" => "Mexico", "continent" => "North America"],
        "FM" => ["country" => "Micronesia", "continent" => "Oceania"],
        "MD" => ["country" => "Moldova", "continent" => "Europe"],
        "MC" => ["country" => "Monaco", "continent" => "Europe"],
        "MN" => ["country" => "Mongolia", "continent" => "Asia"],
        "ME" => ["country" => "Montenegro", "continent" => "Europe"],
        "MS" => ["country" => "Montserrat", "continent" => "North America"],
        "MA" => ["country" => "Morocco", "continent" => "Africa"],
        "MZ" => ["country" => "Mozambique", "continent" => "Africa"],
        "MM" => ["country" => "Myanmar", "continent" => "Asia"],
        "NA" => ["country" => "Namibia", "continent" => "Africa"],
        "NR" => ["country" => "Nauru", "continent" => "Oceania"],
        "NP" => ["country" => "Nepal", "continent" => "Asia"],
        "NL" => ["country" => "Netherlands", "continent" => "Europe"],
        "AN" => ["country" => "Netherlands Antilles", "continent" => "North America"],
        "NC" => ["country" => "New Caledonia", "continent" => "Oceania"],
        "NZ" => ["country" => "New Zealand", "continent" => "Oceania"],
        "NI" => ["country" => "Nicaragua", "continent" => "North America"],
        "NE" => ["country" => "Niger", "continent" => "Africa"],
        "NG" => ["country" => "Nigeria", "continent" => "Africa"],
        "NU" => ["country" => "Niue", "continent" => "Oceania"],
        "NF" => ["country" => "Norfolk Island", "continent" => "Oceania"],
        "MP" => ["country" => "Northern Mariana Islands", "continent" => "Oceania"],
        "NO" => ["country" => "Norway", "continent" => "Europe"],
        "OM" => ["country" => "Oman", "continent" => "Asia"],
        "PK" => ["country" => "Pakistan", "continent" => "Asia"],
        "PW" => ["country" => "Palau", "continent" => "Oceania"],
        "PS" => ["country" => "Palestinia", "continent" => "Asia"],
        "PA" => ["country" => "Panama", "continent" => "North America"],
        "PG" => ["country" => "Papua New Guinea", "continent" => "Oceania"],
        "PY" => ["country" => "Paraguay", "continent" => "South America"],
        "PE" => ["country" => "Peru", "continent" => "South America"],
        "PH" => ["country" => "Philippines", "continent" => "Asia"],
        "PN" => ["country" => "Pitcairn", "continent" => "Oceania"],
        "PL" => ["country" => "Poland", "continent" => "Europe"],
        "PT" => ["country" => "Portugal", "continent" => "Europe"],
        "PR" => ["country" => "Puerto Rico", "continent" => "North America"],
        "QA" => ["country" => "Qatar", "continent" => "Asia"],
        "RE" => ["country" => "Reunion", "continent" => "Africa"],
        "RO" => ["country" => "Romania", "continent" => "Europe"],
        "RU" => ["country" => "Russian Federation", "continent" => "Europe"],
        "RW" => ["country" => "Rwanda", "continent" => "Africa"],
        "SH" => ["country" => "Saint Helena", "continent" => "Africa"],
        "KN" => ["country" => "Saint Kitts and Nevis", "continent" => "North America"],
        "LC" => ["country" => "Saint Lucia", "continent" => "North America"],
        "PM" => ["country" => "Saint Pierre and Miquelon", "continent" => "North America"],
        "VC" => ["country" => "Saint Vincent and The Grenadines", "continent" => "North America"],
        "WS" => ["country" => "Samoa", "continent" => "Oceania"],
        "SM" => ["country" => "San Marino", "continent" => "Europe"],
        "ST" => ["country" => "Sao Tome and Principe", "continent" => "Africa"],
        "SA" => ["country" => "Saudi Arabia", "continent" => "Asia"],
        "SN" => ["country" => "Senegal", "continent" => "Africa"],
        "RS" => ["country" => "Serbia", "continent" => "Europe"],
        "SC" => ["country" => "Seychelles", "continent" => "Africa"],
        "SL" => ["country" => "Sierra Leone", "continent" => "Africa"],
        "SG" => ["country" => "Singapore", "continent" => "Asia"],
        "SK" => ["country" => "Slovakia", "continent" => "Europe"],
        "SI" => ["country" => "Slovenia", "continent" => "Europe"],
        "SB" => ["country" => "Solomon Islands", "continent" => "Oceania"],
        "SO" => ["country" => "Somalia", "continent" => "Africa"],
        "ZA" => ["country" => "South Africa", "continent" => "Africa"],
        "GS" => ["country" => "South Georgia and The South Sandwich Islands", "continent" => "Antarctica"],
        "ES" => ["country" => "Spain", "continent" => "Europe"],
        "LK" => ["country" => "Sri Lanka", "continent" => "Asia"],
        "SD" => ["country" => "Sudan", "continent" => "Africa"],
        "SR" => ["country" => "Suriname", "continent" => "South America"],
        "SJ" => ["country" => "Svalbard and Jan Mayen", "continent" => "Europe"],
        "SZ" => ["country" => "Swaziland", "continent" => "Africa"],
        "SE" => ["country" => "Sweden", "continent" => "Europe"],
        "CH" => ["country" => "Switzerland", "continent" => "Europe"],
        "SY" => ["country" => "Syrian Arab Republic", "continent" => "Asia"],
        "TW" => ["country" => "Taiwan, Province of China", "continent" => "Asia"],
        "TJ" => ["country" => "Tajikistan", "continent" => "Asia"],
        "TZ" => ["country" => "Tanzania, United Republic of", "continent" => "Africa"],
        "TH" => ["country" => "Thailand", "continent" => "Asia"],
        "TL" => ["country" => "Timor-leste", "continent" => "Asia"],
        "TG" => ["country" => "Togo", "continent" => "Africa"],
        "TK" => ["country" => "Tokelau", "continent" => "Oceania"],
        "TO" => ["country" => "Tonga", "continent" => "Oceania"],
        "TT" => ["country" => "Trinidad and Tobago", "continent" => "North America"],
        "TN" => ["country" => "Tunisia", "continent" => "Africa"],
        "TR" => ["country" => "Turkey", "continent" => "Asia"],
        "TM" => ["country" => "Turkmenistan", "continent" => "Asia"],
        "TC" => ["country" => "Turks and Caicos Islands", "continent" => "North America"],
        "TV" => ["country" => "Tuvalu", "continent" => "Oceania"],
        "UG" => ["country" => "Uganda", "continent" => "Africa"],
        "UA" => ["country" => "Ukraine", "continent" => "Europe"],
        "AE" => ["country" => "United Arab Emirates", "continent" => "Asia"],
        "GB" => ["country" => "United Kingdom", "continent" => "Europe"],
        "US" => ["country" => "United States", "continent" => "North America"],
        "UM" => ["country" => "United States Minor Outlying Islands", "continent" => "Oceania"],
        "UY" => ["country" => "Uruguay", "continent" => "South America"],
        "UZ" => ["country" => "Uzbekistan", "continent" => "Asia"],
        "VU" => ["country" => "Vanuatu", "continent" => "Oceania"],
        "VE" => ["country" => "Venezuela", "continent" => "South America"],
        "VN" => ["country" => "Viet Nam", "continent" => "Asia"],
        "VG" => ["country" => "Virgin Islands, British", "continent" => "North America"],
        "VI" => ["country" => "Virgin Islands, U.S.", "continent" => "North America"],
        "WF" => ["country" => "Wallis and Futuna", "continent" => "Oceania"],
        "EH" => ["country" => "Western Sahara", "continent" => "Africa"],
        "YE" => ["country" => "Yemen", "continent" => "Asia"],
        "ZM" => ["country" => "Zambia", "continent" => "Africa"],
        "ZW" => ["country" => "Zimbabwe", "continent" => "Africa"]
    ];

@maruffahmed
Copy link

maruffahmed commented Dec 25, 2018

Thank you bro

@nivla360
Copy link

nivla360 commented Jul 25, 2019

Thanks

Copy link

ghost commented Sep 13, 2019

Javascript Peoples here for You

const countries = ["Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "France Metropolitan", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and Mc Donald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao, People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, The Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia (Slovak Republic)", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "St. Helena", "St. Pierre and Miquelon", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"]

@foremtehan
Copy link

foremtehan commented Dec 27, 2019

I love yall

@nirodaonline
Copy link

nirodaonline commented Dec 29, 2019

Hi guys

Based on https://gist.github.com/DHS/1340150#gistcomment-2323795 I wrote a script to generate a country list file for each language available on the REST API ("en", "de", "es", "fr", "ja", "it", "br", "pt", "nl", "hr", "fa"):

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://restcountries.eu/rest/v2/all');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$countries = json_decode($result);
$file_path = ABSPATH . '/wp-content/plugins/azimut-custom/inc/';
$langs = array("en", "de", "es", "fr", "ja", "it", "br", "pt", "nl", "hr", "fa");

foreach ($langs as $lang) {

    //prepare files
    file_put_contents($file_path . 'countries_'.$lang.'.php',
        "<?php\n\nreturn\n\tarray(\n", FILE_APPEND  );

    foreach ($countries as $country) {

        $country_code = $country->alpha2Code;
        $name = ($lang === 'en') ? $country->name : $country->translations->{$lang};
        file_put_contents($file_path . 'countries_'.$lang.'.php',
            "\t\t".'"'.$country_code.'" => "'.$name.'",'.PHP_EOL, FILE_APPEND  );

    }

    //Close array
    file_put_contents($file_path . 'countries_'.$lang.'.php',
        "\t);", FILE_APPEND  );

}

Hope it's useful!

@MrCrap
Copy link

MrCrap commented Jun 3, 2020

Thanks All..

@her0mx
Copy link

her0mx commented May 27, 2021

Thanks good man!

@git-e-001
Copy link

git-e-001 commented Feb 8, 2022

const countryAlpha2 = [
"AF",
"AL",
"DZ",
"AS",
"AD",
"AO",
"AI",
"AQ",
"AG",
"AR",
"AM",
"AW",
"AU",
"AT",
"AZ",
"BS",
"BH",
"BD",
"BB",
"BY",
"BE",
"BZ",
"BJ",
"BM",
"BT",
"BO",
"BQ",
"BA",
"BW",
"BV",
"BR",
"IO",
"BN",
"BG",
"BF",
"BI",
"CV",
"KH",
"CM",
"CA",
"KY",
"CF",
"TD",
"CL",
"CN",
"CX",
"CC",
"CO",
"KM",
"CD",
"CG",
"CK",
"CR",
"HR",
"CU",
"CW",
"CY",
"CZ",
"CI",
"DK",
"DJ",
"DM",
"DO",
"EC",
"EG",
"SV",
"GQ",
"ER",
"EE",
"SZ",
"ET",
"FK",
"FO",
"FJ",
"FI",
"FR",
"GF",
"PF",
"TF",
"GA",
"GM",
"GE",
"DE",
"GH",
"GI",
"GR",
"GL",
"GD",
"GP",
"GU",
"GT",
"GG",
"GN",
"GW",
"GY",
"HT",
"HM",
"VA",
"HN",
"HK",
"HU",
"IS",
"IN",
"ID",
"IR",
"IQ",
"IE",
"IM",
"IL",
"IT",
"JM",
"JP",
"JE",
"JO",
"KZ",
"KE",
"KI",
"KP",
"KR",
"KW",
"KG",
"LA",
"LV",
"LB",
"LS",
"LR",
"LY",
"LI",
"LT",
"LU",
"MO",
"MG",
"MW",
"MY",
"MV",
"ML",
"MT",
"MH",
"MQ",
"MR",
"MU",
"YT",
"MX",
"FM",
"MD",
"MC",
"MN",
"ME",
"MS",
"MA",
"MZ",
"MM",
"NA",
"NR",
"NP",
"NL",
"NC",
"NZ",
"NI",
"NE",
"NG",
"NU",
"NF",
"MP",
"NO",
"OM",
"PK",
"PW",
"PS",
"PA",
"PG",
"PY",
"PE",
"PH",
"PN",
"PL",
"PT",
"PR",
"QA",
"MK",
"RO",
"RU",
"RW",
"RE",
"BL",
"SH",
"KN",
"LC",
"MF",
"PM",
"VC",
"WS",
"SM",
"ST",
"SA",
"SN",
"RS",
"SC",
"SL",
"SG",
"SX",
"SK",
"SI",
"SB",
"SO",
"ZA",
"GS",
"SS",
"ES",
"LK",
"SD",
"SR",
"SJ",
"SE",
"CH",
"SY",
"TW",
"TJ",
"TZ",
"TH",
"TL",
"TG",
"TK",
"TO",
"TT",
"TN",
"TR",
"TM",
"TC",
"TV",
"UG",
"UA",
"AE",
"GB",
"UM",
"US",
"UY",
"UZ",
"VU",
"VE",
"VN",
"VG",
"VI",
"WF",
"EH",
"YE",
"ZM",
"ZW",
"AX",
]

@dddkkk01
Copy link

dddkkk01 commented Jun 14, 2022

this gist is awesome, saved a lot time for me , thank you all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment