Multiple Arrays and foreach loop
Posted: Thu Feb 26, 2009 6:55 pm
I am not an experienced programmer. I have been searching and can't find the answer anywhere.
I am trying to create a php order form and this is what I would like the output to look like:
Banana.....................$0.49/lb........QTY____
Apple........................$0.99/lb.......QTY____
Orange......................$0.50/ea......QTY____
My attempt was to create arrays. I need to have $fruit, $price, and $unit.
$fruit = array('Banana' => '0.49' , 'Apple' => '22.50' , 'Orange' => '0.50');
I also would like to create an array for the $unit, so that I can keep the $price a numeric value and use it to calculate the price further down the road.
I only found that I can use foreach ($fruit as $price) to populate the table. However, I can't figure out how to use foreach function to work with more than 2 array variables at the same time.
Please let me know if I am heading the right direction and give me some hints how to accomplish this.
Thanks in advance!
Becky
I am trying to create a php order form and this is what I would like the output to look like:
Banana.....................$0.49/lb........QTY____
Apple........................$0.99/lb.......QTY____
Orange......................$0.50/ea......QTY____
My attempt was to create arrays. I need to have $fruit, $price, and $unit.
$fruit = array('Banana' => '0.49' , 'Apple' => '22.50' , 'Orange' => '0.50');
I also would like to create an array for the $unit, so that I can keep the $price a numeric value and use it to calculate the price further down the road.
I only found that I can use foreach ($fruit as $price) to populate the table. However, I can't figure out how to use foreach function to work with more than 2 array variables at the same time.
Please let me know if I am heading the right direction and give me some hints how to accomplish this.
Thanks in advance!
Becky