I currently construct a multi-dim array from my input. like so: (example)
<form method=post action="testing.php">
<input name="response[0]['id']" type="hidden" value="<? echo $q1; ?>">
<input name="response[0]['answer']" type=text value=''>
<input name="response[1]['id']" type="hidden" value="<? echo $q2; ?>">
<input name="response[1]['answer']" type=text value=''>
<input name="response[2]['id']" type="hidden" value="<? echo $q3; ?>">
<input name="response[2]['answer']" type=text value=''>
<input name="response[3]['id']" type="hidden" value="<? echo $q4; ?>">
<input name="response[3]['answer']" type=text value=''>
<input type="submit" value="submit">
</form>
so that is successfully be POSTED. However I am trying to use a foreach to print out the values and I am getting it wrong.
EDIT my output array:
Array (
[0] => Array
(
['id'] => q1
['answer'] => 1
)
[1] => Array
(
['id'] => q2
['answer'] => 2
)
[2] => Array
(
['id'] => q3
['answer'] => 3
)
[3] => Array
(
['id'] => q4
['answer'] => 4
)
)
can somebody explain how i would extract the values with a foreach or even a better way?
many thanks
EDIT
Note the apos (
') are part of the name! Either change the HTML (response[0][id]) or do the following.The incoming array should look like:
Thus,
The problem:
<input name="response[0]['answer']" />will yield an array with'answer'as key. I.e., the literal string with apos, not justanswer. You should probably change the HTML to<input name="response[0][answer]" />to avoid confusion.I will try and see if this is documented behavior.This behavior is indicated in the docs.