php - Getting the value of an associative array with a select box -
php - Getting the value of an associative array with a select box -
i have select box displays keys of associative array, , can observe alternative user chooses. i'm wondering how can create php utilize value of selected key.
$eu = array( "italy"=>"rome", "luxembourg"=>"luxembourg", "belgium"=> "brussels", "denmark"=>"copenhagen", "finland"=>"helsinki", "france" => "paris", "slovakia"=>"bratislava", "slovenia"=>"ljubljana", "germany" => "berlin", "greece" => "athens", "ireland"=>"dublin", "netherlands"=>"amsterdam", "portugal"=>"lisbon", "spain"=>"madrid", "sweden"=>"stockholm", "united kingdom"=>"london", "cyprus"=>"nicosia", "lithuania"=>"vilnius", "czech republic"=>"prague", "estonia"=>"tallin", "hungary"=>"budapest", "latvia"=>"riga", "malta"=>"valetta", "austria" => "vienna", "poland"=>"warsaw"); ksort($eu); ?> <form method="post" action="<?php echo $_server['php_self']; ?>"> <select name="country_select"> <?php foreach ($eu $country => $capital) { ?> <option value="<?php echo $country; ?>"><?php echo $country; ?></option> <?php } ?> </select> <input type="submit" name="submit" value="confirm"> </form> <?php $country = $_post['country_select']; if (isset($_post['submit'])) { echo "the capital city of country, " . $country . ", " . $capital . "."; } ?>
the output displays selected country, says capital city london.
php html
Comments
Post a Comment