Country drop down list with php function

19 November 2011

I had a project recently that required the user to select their country from a drop down list and store the data in a database. It was such a long process setting up the PHP switch statement that I thought someone might find it useful for a project. The code below is a snapshot of the switch statement I've setup. The download at the bottom includes 238 countries and continents. You just need to store the country code in the database then call the function below to return the country name.

Code snapshot

Below is a snapshop of the PHP switch statement. Download the full code of the tutorial here. Upload the PHP file included and see the demos.

function user_country($country){


case 'AF':
$name = 'Afghanistan';

case 'AL':
$name = 'Albania';

case 'DZ':
$name = 'Algeria';


return array(

"name" => $name




Again this is a snapshot of the select drop down form.

    <select name="country">
      <option value="AF">Afghanistan</option>
      <option value="AL">Albania</option>
      <option value="DZ">Algeria</option>

Sumber : Jasa Pembuatan Website dan Sistem Informasi
Selengkapnya :