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>

Technorati Tags: , ,


One Response to “php: Dynamically fill a select box”

  1. Zuka Says:

    Thanks, I was having trouble with this.

Post A Comment