我正在尝试从下拉列表中捕获多个选项并通过邮件发送。 我试过以下代码。
HTML:
<select name="thelist[]" multiple="multiple">
<option value="Value 1">Value 1</option>
<option value="Value 2">Value 2</option>
</select>
PHP
if( is_array($thelist))
{
while (list ($thelist) = each ($thelist))
{
echo "$thelist <br>";
}
}
else{echo "not working";}
请帮帮我。
答案 0 :(得分:1)
$thelist = $_POST['thelist'];
if(is_array($thelist)){
foreach($thelist as $item){
echo $item.'<br>';
}
}else{
echo 'thelist is not an array';
}
答案 1 :(得分:1)
将thelist[]
更改为thelist
,因为您的命名方式不同并且使用不同的名称,请执行以下操作:
<select name="thelist" multiple="multiple">
<option value="Value 1">Value 1</option>
<option value="Value 2">Value 2</option>
</select>
正如塞缪尔所说:
$thelist = $_POST['thelist'];
if(is_array($thelist)){
foreach($thelist as $item){
echo $item.'<br>';
}
}else{
echo 'thelist is not an array';
}