Below is my code I am trying to get to work but I really have very little knowledge of array and foreach. So it doesn;t work correctly
I need to show a dropdown select form to the browser with the contents of the array I also need to have the item selected if it is == to $mycountry Lastly I would like to show the USA and UK at the top of my list
Can anyone tell me how I can do al this
<?PHP
$countries = array(
"217" => "Turkenistan",
"218" => "Turks and Caicos Islands",
"219" => "Tuvalu",
"220" => "Uganda",
"221" => "Ukraine",
"222" => "United Arab Emirates",
"223" => "United Kingdom (Great Britain)",
"224" => "United States");
$mycountry = 224;
?>
<select name="country" style="width:180px;" onChange="do_get_rest_popup(this.value)" />
<?php
$countryCounter = 1;
$amtOfCountries = count($countries);
//foreach ($country as $id => $c) {
for( $_top=0; $_top < $amtOfCountries; $_top++ ){
if ($countryCounter == $amtOfCountries) {
echo "<option value=\"$countries[0]\" SELECTED>$countries[1]</option>";
} else {
echo "<option value=\"$countries[0]\">$countries[1]</option>";
$countryCounter++;
}
}
?>
</select>