I have an IF statement to check for a specific string within a ForEach loop and if present then add 'selected' to the output so that entry is displayed first within an HTML select box. However when the loop reaches the correct record it adds 'selected' every subsequent record.
function adminFillOption($options, $input) {
$output = "";
$selected = "";
//iterate through the array
foreach ($options as $value => $desc) {
if ($input == $desc) {
$selected = 'selected';
};
//Add an option for each elemement of the array to the output
$desc = htmlspecialchars($desc);
$output .= "\t\t\t\t\t\t<option value='$desc' $selected >$desc</option>\n";
}//end interation
return $output;
}
Any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire