Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,143,240 members, 7,780,472 topics. Date: Thursday, 28 March 2024 at 03:06 PM

Array Of Countries And Cities In Php - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Array Of Countries And Cities In Php (2814 Views)

Using 2-dimensional Array In C++ / Complete Array Of Countries And Nigerian States [open Source] / Converting Picture To Byte Array(blob) And Back To Picture (2) (3) (4)

(1) (Reply)

Array Of Countries And Cities In Php by leastpay(m): 3:16pm On Nov 25, 2012
Pls programmers i'm developing a form that need to display all countries, state and city in nigeria into a dropdownlist using php. Pls i need the code and explain how it is achieve. Thanks
Re: Array Of Countries And Cities In Php by Kwestc: 11:47pm On Nov 25, 2012
I think this should help

<?php

$state = "Abuja,Anambra,Enugu,Akwa Ibom,Adamawa,Abia,Bauchi,Bayelsa,Benue,Borno,Cross River,Delta,Ebonyi,Edo,Ekiti,Gombe,Imo,Jigawa,Kaduna,Kano,Katsina,Kebbi,Kogi,Kwara,Lagos,Nasarawa,Niger,Ogun,Ondo,Osun,Oyo,Plateau,Rivers,Sokoto,Taraba,Yobe,Zamfara"


$city = "Aba,Abakaliki,Abeokuta,Abuja,Akure,Asaba,Anambra,Atlanta,Awka,Bauchi,Benin City,Birnin Kebbi,Calabar,Dutse,Eket,Enugu,Gombe,Gusau,Ibadan,Ife,Ikeja,Ikot-Abasi,Ikot Ekpene,Ikoyi,Ilorin,Jalingo,Jimeta,Jos,Kaduna,Kano,Katsina,Karu,Kumariya,Lafia,Lagos,Lokoja,Maiduguri,Makurdi,Minna,Nsukka,Ogbomoso,Onitsha,Oron,Oshogbo,Owerri,Owo,Oyo,Port Harcourt,Potiskum,Sokoto,Suleja,Umuahia,Uyo,Warri,Wukari,Yenagoa,Yola,Zaria";


/*
Function to format an array into a <select> tag

@param: $arr - The array to be converted.
@param: $field - The attribute name of the <select> tag

Usage: <form>
...
...
FormatSelect( $state, "State" );
...
FormatSelect( $city, "City" );
...
</form>

Prototype: String FormatSelect( Array $arr, String $field )
*/

function FormatSelect( $arr, $field ) {

$options = explode( ",", $arr );

$selectTag = '<select name="' .$field. '">';

foreach( $options as $key => $option ) {

$selectTag .= '<option value="'.$option.'">'. $option .'</option>' . "\n";
}

$selectTag .= '</select>';

return $selectTag;

}

?>

(1) (Reply)

Where Can I Learn Programming In Illorin? / I Need A Good Software Developer / Reasons Why Nigerian Tech Companies Pay Poorly.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.