Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of multiple select inputs

I have this form :

<form>
    <select name="data[][]" multiple="multiple">
        <option>1</option>
        <option selected="selected">2</option>
    </select>

    <select name="data[][]" multiple="multiple">
        <option selected="selected">3</option>
        <option>4</option>
    </select>

    <select name="data[][]" multiple="multiple">
        <option selected="selected">5</option>
        <option selected="selected">6</option>
    </select>
</form>

I would like to get this :

$_POST['data'] = array(
    0 => array(2),
    1 => array(3),
    2 => array(5,6)
);

I instead get this :

$_POST['data'] = array(
    0 => array(2),
    1 => array(3),
    2 => array(5),
    3 => array(6)
);

The solution would be to set the index : name="data[0][]" but i want it to be automatically done ..

Any ideas?

like image 794
Yuukuari Avatar asked Oct 20 '22 16:10

Yuukuari


1 Answers

One way.Change to :

<select name="data[0][]" multiple="multiple"> 
 ...
<select name="data[1][]" multiple="multiple">
 ...
<select name="data[2][]" multiple="multiple">

Also see @CBroe comment.

like image 88
voodoo417 Avatar answered Oct 26 '22 22:10

voodoo417