I have a table with four columns across and five rows down. Within each cell, is a combination of the row and the column. Each cell contains a checkbox, and the user can indicate the combination of rows and columns that apply to him.
I currently have each checkbox coded like this:
<input type="checkbox" name="var[<?=$colnum;?>]" value="<?=$rownum;?>">
(I've also tried name="var[<?=$colnum;?>][]")
What you end up with is a multidimensional array containing each combination or rows and columns that's been selected.
When I process this form, I need to know which combinations were selected. So, I've been attempting to run through this with foreach. Just to see if the variables are right, I do this:
foreach ($_POST['var'] AS $key => $value) {
echo "Column: $key<br>";
echo "Row: $value<br><br>";
}
However, this only gives me a single result for each column, even if multiple rows are selected for that column. Also, the row result shows up as "Array."
So, I tried this:
foreach ($_POST['var'] AS $key) {
foreach ($key AS $value) {
echo "Column: $key<br>";
echo "Row: $value<br><br>";
}
}
This gives me the right number of results, but now Column says "Array."
What am I doing wrong here?
Thanks.