Here is what i tried but it is not working. Any clue why or anyone has any code snippets to pass across. Also the fields in this
form are transported to an xml and i get the index value(0,1,2 or 3) of selected option in test dropdown rather than it's
value(No,abc,xyz or efg)
$option = array(0 => 'No', 1 => 'abc', 2 => 'xyz', 3 => 'efg');
$selected = (isset($_POST['test']) && intval($_POST['test']) < 4) ? $_POST['test'] : ''; //index of dropdown
echo "<select name=\"test\">\n";
echo createOptionFromArray($option,$selected);
echo "</select>\n";
function createOptionFromArray($myArray,$selected) {
if(!is_array($myArray)) {
return false;
}
$returned = $select = '';
foreach($myArray as $key => $value) {
if($selected == $key) {
$select = ' selected';
}
$returned .= "<option value=\"$key\"$select>$value</option>";
$select = '';
}
return $returned;
}