You'll have to check the syntax, but the idea works. You create a flag and set it to true before you go through the array of dynamic values. It writes the selected attribute in the option tag for the first item of the array and then sets the flag to false. As you keep iterating through the array, the command to write the selected attribute is ignored.
Code:
<?
$firsttime = true;
echo "<select>";
foreach ($dataarray as $value) {
echo "<option value=\"$value\"";
if ($firsttime) {
echo " selected=\"selected\"";
$firstime = false;
}
echo ">$value</option>";
}
echo "</select>";
?>
Bookmarks