使用 PHP 中的数组自动填充选择框
- 作者: 守护么么哒
- 来源: 51数据库
- 2022-11-01
问题描述
如果我有一个选择框
<select><option>...<option></select>
我有一个从 1 到 12 的值数组
and I had an array of values from 1-12
使用 php,我将如何使用该数组自动填充该选择框?
using php, how would I auto populate that select box using that array?
推荐答案
假设数组如下:
$array = array(
1=>"My first option",
2=> "My second option"
);
<select>
<?php foreach($array as $key => $value) { ?>
<option value="<?php echo $key ?>"><?php echo $value ?></option>
<?php }?>
</select>
推荐阅读
