Setting defaults in a multi-valued
<?
$main_dishes = array('cuke' => 'B',
'stomach' => "B",
'tripe' => 'C',
'taro' => 'S',
'giblets' => 'E',
'abalone' => 'F');
print '<select name="main_dish[]" multiple="multiple">';
$selected_options = array();
foreach ($defaults['main_dish'] as $option) {
$selected_options[$option] = true;
}
foreach ($main_dishes as $option => $label) {
print '<option value="' . htmlentities($option) . '"';
if ($selected_options[$option]) {
print ' selected="selected"';
}
print '>' . htmlentities($label) . '</option>';
print "\n";
}
print '</select>';
?>
Related examples in the same category