php: Dynamically fill a select box
One way to fill a select box with array elements.
<html>
<head>
<title>Select Box</title>
</head>
<body>
< ?php
$myArray = array('cat' , 'dog' , 'mouse' , 'cow');
?>
<select name="myselect">
<option value=""></option> // Sets blank entry *optional*
< ?php
foreach($myArray as $value){ // Loop through each element
print("<option value=\"$value\">$value<option>");
}
?>
</option></select>
</body>
</html>
Categories: Programming, php
Thanks, I was having trouble with this.