How to access the values selected in the multiselect dropdown list in PHP?

两盒软妹~` 提交于 2019-12-05 17:05:04

Modified name as array in select

<select id="selectShift" name="selectShift[]" multiple="multiple">

and did like this and it works

$shiftarraycalc = array();
$shift=$_POST['selectShift'];

if ($shift)
{
    foreach ($shift as $value)
    {
        array_push($shiftarraycalc,$value);
    }
}

You could do like this too.

<form action="ResultsDulith.php" id="intermediate" name="inputMachine[]" multiple="multiple" method="post">
    <select id="selectDuration" name="selectDuration[]" multiple="multiple"> 
        <option value="1 WEEK" >Last 1 Week</option>
        <option value="2 WEEK" >Last 2 Week </option>
        <option value="3 WEEK" >Last 3 Week</option>
         <option value="4 WEEK" >Last 4 Week</option>
          <option value="5 WEEK" >Last 5 Week</option>
           <option value="6 WEEK" >Last 6 Week</option>
    </select>
     <input type="submit"/> 
</form>

Then take the multiple selection from following PHP code below. It print the selected multiple values accordingly.

$shift=$_POST['selectDuration'];

print_r($shift);
<select id="hanu" name="hanu[]" multiple="multiple">
<option> one</option>
<option> two </option>
<option> three</option>
<option> four </option>
<option> five</option>
<option> six </option>
<option> seven</option>
</select>`

And The php code for this is

$res_hanu = array();
$hanu_new=$_POST['hanu'];
if ($hanu_new){
foreach ($hanu_new as $value){
array_push($res_hanu,$value);
}
}
aftab
$shift=$_POST['selectShift'];

if ($shift)
{
    foreach ($shift as $value)
    {
        $shiftarraycalc[]=$value;
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!