2D Dynamic Array from HTML Form - Possible?

From: Date: Mon, 13 Nov 2000 21:36:47 +0000
Subject: 2D Dynamic Array from HTML Form - Possible?
Groups: php.general 
Request: Send a blank email to php-general+get-25035@lists.php.net to get a copy of this message
I have a need to generate anumber of 2D arrays from an HTML form, this is because the number of text fields / sub fields is generated according to other criteria. I have no problem getting a single dimension array back from the form, but 2D array's don't work, any ideas? Currently the HTML looks similar to; <input type="text" name="offer_group[]" size="10"> <input type="text" name="offer_line[][]" size="10"> <input type="text" name="offer_line[][]" size="10"> <input type="text" name="offer_line[][]" size="10"> <input type="text" name="offer_group[]" size="10"> <input type="text" name="offer_line[][]" size="10"> <input type="text" name="offer_group[]" size="10"> <input type="text" name="offer_line[][]" size="10"> The offer_group array is fine, it is offer_lines that doesn't come back, or if I play about comes back as a 1D array. Becuase these are all generated from within a for loop, so I have tried changing the offer_lines HTML output to; <input type="text" name="offer_line[0][]" size="10"> <input type="text" name="offer_line[0][]" size="10"> <input type="text" name="offer_line[0][]" size="10"> <input type="text" name="offer_line[1][]" size="10"> etc, etc. None of this works, I have a solution but that involves passing hidden values in the form, I would rather avoid this as I want to process the data based on what IS there, not what SHOULD be there. I hope you follow. Has anyone any experience of 2D arrays from HTML? If so, what is the correct method of checking the size of the second dimension, in the same manner that count () checks a single array, I was hoping count(offer_line[0]) or similar, but obviously the fact that the array's aren't constructed properly didn't help ;-) Finally, is it true that the good old 'for each' loop doesn't work in PHP3, the site ref claims it's true, surely this must be a boo boo? If not what's the best alternative (hence my need to be able to count the sum of the 2nd array dimension :-( ) I know of the 'while each' loop but that looks far too messy and involves using key/value pairs which I thought were hashes not arrays? Anyway, enough rambling, any pointers would be useful, I've been through most of the PHP Manual but nothing jumped out. -- Andy Flisher 'All postings are a reflection of my state of mind, and not necessarily of any worthwhile opinion' news@flish.co.uk http://www.flish.co.uk

« previous php.general (#25035) next »