Aug 16, 2006 #1 ZOR Technical User Joined Jan 30, 2002 Messages 2,963 Location GB Is it permitted to make a form posted variable an array? eg. $_POST['SOMETHING'][1] $_POST['SOMETHING'][2] etc,etc. instead of: $_POST['SOMETHING1'] $_POST['SOMETHING2'] Thanks
Is it permitted to make a form posted variable an array? eg. $_POST['SOMETHING'][1] $_POST['SOMETHING'][2] etc,etc. instead of: $_POST['SOMETHING1'] $_POST['SOMETHING2'] Thanks
Aug 16, 2006 1 #2 sleipnir214 Programmer Joined May 6, 2002 Messages 15,350 Location US Sure. It's even documented in the online manual: http://www.php.net/manual/en/faq.html.php#faq.html.arrays Want the best answers? Ask the best questions! TANSTAAFL! Upvote 0 Downvote
Sure. It's even documented in the online manual: http://www.php.net/manual/en/faq.html.php#faq.html.arrays Want the best answers? Ask the best questions! TANSTAAFL!
Aug 16, 2006 2 #3 MikeBronner Programmer Joined May 9, 2001 Messages 756 Location US This comes into play when you have more than one field with the same name on your form: Code: <form> <input name="test" [...] /> <input name="test" [...] /> <input name="test" [...] /> </form> You would then access these as: Code: $_POST["test"][0] $_POST["test"][1] $_POST["test"][2] More often, though, you will encounter this when trying to parse multi-selects: Code: <form> <select multiple="true" name="test[]"> <option value="1" selected="true">One</option> <option value="2" selected="true">Two</option> <option value="3" selected="true">Three</option> </select> </form> And you would then access these as: Code: $_POST["test"][0] $_POST["test"][1] $_POST["test"][2] Take Care, Mike Upvote 0 Downvote
This comes into play when you have more than one field with the same name on your form: Code: <form> <input name="test" [...] /> <input name="test" [...] /> <input name="test" [...] /> </form> You would then access these as: Code: $_POST["test"][0] $_POST["test"][1] $_POST["test"][2] More often, though, you will encounter this when trying to parse multi-selects: Code: <form> <select multiple="true" name="test[]"> <option value="1" selected="true">One</option> <option value="2" selected="true">Two</option> <option value="3" selected="true">Three</option> </select> </form> And you would then access these as: Code: $_POST["test"][0] $_POST["test"][1] $_POST["test"][2] Take Care, Mike
Aug 16, 2006 Thread starter #4 ZOR Technical User Joined Jan 30, 2002 Messages 2,963 Location GB Excellent, or hip,hip,array. That makes my life a bit easier. Many thanks again Upvote 0 Downvote