Accessing dynamic form fields

In my code I have form fields like so:

[php]

£ £[/php]

With each row thats is added the “item[’. 1 .’][desc]” part goes up by one. How would I go about accessing these values in PHP. If it helps what I would like to do it take the quantity and code values and put it into two comma separated value lists. The rest is just dressing. [/code]

Normally I would just do item[1].

If you really need to do it with the [’. x .’] format, several different methods are illustrated in this example:[php]<?php
$item = array(’. 1 .’=>array(‘code’=>‘abc’,‘desc’=>‘pickle jar’,‘price’=>’$12.50’,‘quantity’=>2),’. 2 .’=>array(‘code’=>‘def’,‘desc’=>‘pet hamster’,‘price’=>’$12.95’,‘quantity’=>1));

for($i=1;$i<=2;$i++)
{
echo 'Code: ',$item[". $i ."][‘code’],"
";
echo 'Description: ',$item[". $i ."][‘desc’],"
";
echo “Price: {$item[”. $i ."][‘price’]}
";
echo “Quantity: {$item[”. $i ."][“quantity”]}

";
}[/php]

I got it! :smiley: Thanks. :slight_smile: I didn’t know it was an array that would come though. Makes sense now. Cheers.

Glad it will work for you!

Best,

jay

Sponsor our Newsletter | Privacy Policy | Terms of Service