Re: Arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You can absolutely use arrays as form field names. They allow great flexibility. Although you wouldn't use quotes for the array keys.
So your form field name would be something like:
att[keyname]


While in PHP, the same array would look like:
$att['keyname']

Your array "id's" are consider keys since they are not sequential. Just treat them as names for the array entry. There are a number of ways to reference it.
$att = $_POST['att'];
foreach($att as $attkey=>$attval) {
echo $att[$attkey];
echo $attval;
}


Or you could use the array_keys functions to get the keys to the array in it's own array that can be referenced sequentially.
$att = $_POST['att'];
$attkeys = array_keys($att);
echo $att[$attkeys[0]];
echo $att[$attkeys[1]];
etc.



You can even use multidimensional arrays as form field names, which is helpful when you need to keep separate form fields related. Like having multiple phone number/phone description fields:
<input type="text" name="phone[home][desc]" value="Vacation Home" size="10">
<input type="text" name="phone[home][number]" value="123456789" size="10">


<input type="text" name="phone[work][desc]" value="Uptown Office" size="10">
<input type="text" name="phone[work][number]" value="123456789" size="10">



On Dec 28, 2004, at 10:52 PM, GH wrote:

Would it be possible in a form fields name to make it an array?

This way it would be i.e. att[$part_id]

Now is there a way to iterate through the array when I submit the form
to process it, being that the ID numbers are not going to be
sequential and that there will be some numbers not included?

I.E. the id's would be 1, 5, 6, 7, 20, 43

and how would I refence it? would it be $_POST['att']['[partIDhere}'] ?

Thanks
G

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux