Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

posting multidimensional array from checkbox

I have seen a couple of questions regarding posting arrays from checkboxes, however I havent seen anything attempting to do what I want to do.

I have a list of checkboxes that submit data populated in foreach loop of data from a database.

<input type="checkbox" name="phonelist[]" value="<?=strtoupper($device['id']);?>"/>

This is how I am currently returning multiple items for the checkbox phone list. Howver is it possible to add another value in the same value section of the checkbox but under a different item in a multidimensional array? e.g

<input type="checkbox" name="phonelist[][]" value="<?=strtoupper($device['id']);?><?=strtoupper($device['another value']);?>"/>

Im aware my "Psuedocode" is wrong but I hope it gets across the idea I wish to achieve.

like image 660
Mr Sorbose Avatar asked Nov 30 '25 15:11

Mr Sorbose


1 Answers

Yes, add id for each section:

<input type="checkbox" name="phonelist[0][]" value="<?=strtoupper($device['id']);?><?=strtoupper($device['another value']);?>"/>
<input type="checkbox" name="phonelist[0][]" value="<?=strtoupper($device['id']);?><?=strtoupper($device['another value']);?>"/>
<input type="checkbox" name="phonelist[1][]" value="<?=strtoupper($device['id']);?><?=strtoupper($device['another value']);?>"/>
<input type="checkbox" name="phonelist[1][]" value="<?=strtoupper($device['id']);?><?=strtoupper($device['another value']);?>"/>
like image 188
Mihai Iorga Avatar answered Dec 03 '25 06:12

Mihai Iorga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!