Array Of Countries And Cities In Php - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Array Of Countries And Cities In Php (3039 Views)
1 Reply
| Array Of Countries And Cities In Php by leastpay(op): 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; } ?> |
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
Wordpress Or Build From Scratch, Which Is It To Be? • "oracle",is It Losing It's Demand In Today's Nigerian Labor Market? • Feature You Like The Most About Your Favorite Programming Language?