我想用一个数组填充一个选项列表。这是我已经得到的:
$array = array("Amy" , "Steve", "Tim", "Ron");
foreach ($array as $option) {
// Do something (what I dont know how to do:-))
}
我想用一个数组填充一个选项列表。这是我已经得到的:
$array = array("Amy" , "Steve", "Tim", "Ron");
foreach ($array as $option) {
// Do something (what I dont know how to do:-))
}
您好,添加以下代码:
echo "<select>";
foreach ($array as $option)
echo "<option value='" . $option ."'>" . $option . "</option>";
echo "</select>";
希望这可以帮助!
您需要阅读HTML:
<select>
<?php foreach ($array as $key => value) : ?>
<option value="<?php echo $key ?>">
<?php echo $value ?>
</option>
<?php endforeach ?>
</select>