...

View Full Version : $_POST a 2D array?



john6
10-10-2012, 06:19 AM
I have an unknown number of check-boxes in a form (generated by php) that the end-user will tick. How can I do 2D arrays for that?

I.e.

OptionA:
[ ] Tickbox 1
[ ] Tickbox 2
[ ] Tickbox 3

OptionB:
[ ] Tickbox 1
[ ] Tickbox 2
[ ] Tickbox 3

And then get the values like:

_POST[OptionA][1,2,3,4,5..]
_POST[OptionB][1,2,3..]

etc.?

Thanks!

sunfighter
10-10-2012, 05:33 PM
easier than me trying to explain: http://www.w3schools.com/html/html_forms.asp

Len Whistler
10-10-2012, 05:57 PM
You use a foreach loop. The example below is a quick one so there might be syntax errors. You can also assign the output to variables, instead of echoing it out.



$array = _POST['OptionA']; // 0,1,2,3,4,5,6 .........

foreach ($array as $value) {
echo "$value";
}




-----

Wuteverx1972
10-10-2012, 08:14 PM
Try using an array + foreach loop:



$arr = array ('options' => $_POST['option1'], $_POST['option2'],$_POST['option3'], $_POST['option4']);
$output= "";
foreach ($arr as $arr) {
$value .= $arr.", ";
}
echo $output;


You can store the $output into your database, however it may be difficult to analyze the data after... There is better method to store multiple values for data analysis but that's my 2 cents.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum