-1

我想用一个数组填充一个选项列表。这是我已经得到的:

$array = array("Amy" , "Steve", "Tim", "Ron");

foreach ($array as $option) {


// Do something (what I dont know how to do:-))
}
4

2 回答 2

1

您好,添加以下代码:

echo "<select>";
foreach ($array as $option)
    echo "<option value='" . $option ."'>" . $option . "</option>";
echo "</select>";

希望这可以帮助!

于 2013-10-02T11:56:23.927 回答
1

您需要阅读HTML

<select>
    <?php foreach ($array as $key => value) : ?>
        <option value="<?php echo $key ?>">
            <?php echo $value ?>
        </option>
    <?php endforeach ?>
</select>
于 2013-10-02T12:02:31.940 回答