I have a form elements in loop and one of them is select box with multiple select option. Here is the code.
<?php for($i = 1; $i <= 2; $i++){ ?>
<input type="text" name="product[]" />
<select name="problems[]"
<option value="problem1">Problem 1</option>
<option value="problem2">Problem 2</option>
<option value="problem3">Problem 3</option>
</select>
<?php } ?>
I enter product "TV ", choose 2 option for product "TV" i.e. problem1 and problem2 and all 3 option for another product Fridge. When i submit the form print the post data, i get data in array
Array
(
[product] => Array
(
[0] => TV
[1] => Fridge
)
[problems] => Array
(
[0] => problem1
[1] => problem2
[2] => problem1
[3] => problem1
[4] => problem3
)
)
Here, i could not check which problems are of which product. What i want is like this
Array
(
[product] => Array
(
[0] => TV
[1] => Fridge
)
[problems] => Array
(
[0] => Array
(
[0] => problem1
[1] => problem2
)
[1] => Array
(
[0] => problem1
[1] => problem2
[2] => problem3
)
)
)
Is there any way to get array in this way? Your help is highly appreciated.