php array and foreach? -
Below is my code. I'm trying to work, but I actually have very little knowledge of array and foreign language Then it does not work correctly
I have to show a dropdown form in the browser with the content of the array, I also need to select the item if it is == $ mycountry, then finally I have to show to the United States and the UK at the top of my list Can anyone tell me how I can do this
"Turks and Caicos Islands", "21 9" =>
"Tuvalu", "220" => "Uganda", "221" = & gt; "Ukraine", "222" = & gt; "United Arab Emirates", "223" => "United Kingdom (Great Britain)", "224" => ;" United States of america "); $ Mycountry = 224; ? & Gt; & Lt; Select name = "country" style = "width: 180px;" Onchange = "do_get_rest_popup (this.value)" /> & Lt ;? Php $ countryCounter = 1; $ AmtOfCountries = Count ($ country); // $ for foreach ($ id = & gt; $ c) {$ ($ _top = 0; $ _top
foreach (dollar $ as $$ countries => gt; ; $ Country) {$ selected = "" if ($ key == $ mycountry) $ selected = 'selected =' selected ''; Print '& lt; Option value = '. $ Key $ selected '' & gt; . $ Country '& lt; / Option & gt; '; }
Basically, for each element within the array, you are breaking it into its key and its value (i.e. $ countreis [key] = value). Once you take your head around arrays (and they can be very confusing) it will codify a million times easier.
(Syntax highlighting / formatting is not working in my code for some reasons ...)
Comments
Post a Comment