[英]Pass values in an array as select form
I have this part here which generates me an array: 我在这里有这部分,生成了一个数组:
$ids_sektor = explode("/",$row['sektori']);
What i need is to echo all those values inside a select option... The html for my selectbox is: 我需要的是在选择选项中回显所有这些值。我的选择框的html是:
<select id="sektori_pergjegjes" name="sektori_pergjegjes">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
I tried foreach but no success, i guess i'm doing something wrong, of cours ei am, some help please. 我尝试过foreach,但没有成功,我想我做错了,当然,请帮忙。
It should work as follows: 它应如下工作:
$row['sektori'] = "12/34/56";
$ids_sektor = explode("/", $row['sektori'];
foreach ($ids_sektor as $id) {
echo "<option>$id</option>\n";
}
I'm not sure I understood the question well, but it should be done like that: 我不确定我是否很好地理解了这个问题,但是应该这样做:
<select id="sektori_pergjegjes" name="sektori_pergjegjes">
<?php
foreach($ids_sektor as $item)
{
$id = htmlspecialchars(item);
echo('<option value="' . $id . '">' . $id . '</option>');
}
?>
</select>
You may skip htmlspecialchars()
when you're 100% sure there will be just A/B/C/D/E
in your array. 当您100%确定数组中只有
A/B/C/D/E
,可以跳过htmlspecialchars()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.