Re: [PHP] There Has to be an easier way (Multidimensional Array_
On Tuesday 03 December 2002 23:45, Dev wrote: Hello all Currently I have a web fom that has 3 field in it that I want writing to a multidimensional array. TR TDINPUT TYPE=text NAME=address[] VALUE=/TD TD WIDTH=50 ALIGN=centerINPUT TYPE=text NAME=address[]['state'] VALUE= SIZE=5 MAXLENGTH=5/TD TD COLSPAN=2INPUT TYPE=text NAME=address[][]['zip'] VALUE=/TD /TR I would name them as: NAME=address[][address] NAME=address[][state] NAME=address[][zip] (I'm assuming you have multiple addresses on a single form) Then loop through them by: foreach ($address as $key = $value) { echo Address: {$value['address']} State: {$value['state']} Zip: {$value['zip']}; } For a single address use: NAME=address[address] NAME=address[state] NAME=address[zip] And no need to loop, just use the values directly. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* The best portion of a good man's life, his little, nameless, unremembered acts of kindness and love. -- Wordsworth */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] There Has to be an easier way (Multidimensional Array_
Thank you That works great! At 11:56 PM 12/3/2002 +0800, Jason Wong wrote: On Tuesday 03 December 2002 23:45, Dev wrote: Hello all Currently I have a web fom that has 3 field in it that I want writing to a multidimensional array. TR TDINPUT TYPE=text NAME=address[] VALUE=/TD TD WIDTH=50 ALIGN=centerINPUT TYPE=text NAME=address[]['state'] VALUE= SIZE=5 MAXLENGTH=5/TD TD COLSPAN=2INPUT TYPE=text NAME=address[][]['zip'] VALUE=/TD /TR I would name them as: NAME=address[][address] NAME=address[][state] NAME=address[][zip] (I'm assuming you have multiple addresses on a single form) Then loop through them by: foreach ($address as $key = $value) { echo Address: {$value['address']} State: {$value['state']} Zip: {$value['zip']}; } For a single address use: NAME=address[address] NAME=address[state] NAME=address[zip] And no need to loop, just use the values directly. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* The best portion of a good man's life, his little, nameless, unremembered acts of kindness and love. -- Wordsworth */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] There Has to be an easier way (Multidimensional Array_
An important thing to note in general, if you do: input name=address[][address] value=test1 input name=address[][city] value=test2 input name=address[][state] value=test3 On the page your submitting to, you'll end up with: $address[0][address] $address[1][city] $address[2][state] Where as you were expecting to get: $address[0][address] $address[0][city] $address[0][state] This happens because when you use the [] operator to say to PHP next array position, every time it hits that it increments the row, rather then understanding your trying to say set this value on this array row, it hears woah, I just saw a [] so I'm going to up the row. -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part