将多选选项存储到 PHP 数组中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17957588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
store multiple select option into a PHP array
提问by vahid
I have an selectbox list Is it possible to select multiple option:
我有一个选择框列表 是否可以选择多个选项:
<select name="access_list[ ]" size="7" multiple="multiple">
<?php $res=mysql_query("select * from list" ,$conn);
while($row=mysql_fetch_assoc($res))
echo"<option value=".$row['id'].">".$row['name']."</option>";?>
</select>
How do the values ??that will be selected (select multiple values ??together) can be stored in the array. I think that will do it for each order?
将被选择的值(选择多个值?一起)如何存储在数组中。我认为每个订单都会这样做吗?
回答by Bora
Use name as name="access_list[]"
without space.
使用name="access_list[]"
没有空格的名称。
And you can get selected options with $_POST['access_list']
你可以得到选定的选项 $_POST['access_list']
$_POST['access_list']
is array
that contains selected options
$_POST['access_list']
是array
包含选定的选项
回答by Erman Belegu
Replace your select tag with this:
用这个替换你的选择标签:
<select name="access_list[]" size="7" multiple="multiple">
If you want to get the array, you can do it like this:
如果你想得到数组,你可以这样做:
$data = $_POST['access_list'];
print_r($data);
回答by Shaiful Ezani
store as array then in your php is like this.
存储为数组然后在你的 php 中是这样的。
<?php
$access_list = $_POST['access_list'];
foreach($access_list as $value)
{
//Do your code Here
}
?>