Using a multi-dimensional array in a POST form?
| From: | Daevid Vincent | Date: | Fri, 14 Jan 2005 23:47:11 +0000 |
| Subject: | Using a multi-dimensional array in a POST form? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-206404@lists.php.net to get a copy of this message | ||
I have a lot of data I want to associate with a single line item in table of
data. The current method (which feels messy to me) is to do this....
<INPUT TYPE=HIDDEN VALUE="range_1" NAME="userange[1111]">
<INPUT TYPE=HIDDEN VALUE="scanner_1" NAME="usescanner[1111]">
<INPUT TYPE=HIDDEN VALUE="record_1" NAME="userecord[1111]">
<INPUT TYPE=HIDDEN VALUE="range_2" NAME="userange[2222]">
<INPUT TYPE=HIDDEN VALUE="scanner_2" NAME="usescanner[2222]">
<INPUT TYPE=HIDDEN VALUE="record_2" NAME="userecord[2222]">
Which gives me this:
_POST[userange] => Array
(
[1111] => range_1
[2222] => range_2
)
_POST[usescanner] => Array
(
[1111] => scanner_1
[2222] => scanner_2
)
_POST[userecord] => Array
(
[1111] => record_1
[2222] => record_2
)
What I'd like to do is this:
<INPUT TYPE=HIDDEN VALUE="range_1" NAME="device[1111][range]">
<INPUT TYPE=HIDDEN VALUE="scanner_1" NAME="device[1111][scanner]">
<INPUT TYPE=HIDDEN VALUE="record_1" NAME="device[1111][record]">
<INPUT TYPE=HIDDEN VALUE="range_2" NAME="device[2222][range]">
<INPUT TYPE=HIDDEN VALUE="scanner_2" NAME="device[2222][scanner]">
<INPUT TYPE=HIDDEN VALUE="record_2" NAME="device[2222][record]">
When I submit the form, it appears to work as illustrated by this print_r():
_POST[device] => Array
(
[1111] => Array
(
[range] => range_1
[scanner] => scanner_1
[record] => record_1
)
[2222] => Array
(
[range] => range_2
[scanner] => scanner_2
[record] => record_2
)
)
However, I don't seem to be able to access the elements?!
I've tried various combinations of tick marks on both the hidden input and
also on the retrieval to no avail...
Ie. <INPUT TYPE=HIDDEN VALUE="range_2"
NAME="device[2222]['range']">
And echo "device[2222][range] = ".$device[2222]['range'];
or echo "device[2222][range] = ".$device[2222][range];
Is this possible?