Thanks to the people who have responded. Much appreciated. Apologies but I still do not have a grasp on the solutions provided. Sorry if I didn't make myself clear and (for Spring) my understanding of arrays and loops is limited to copying others' existing code and modifying.
I think it may be better for me to ask the question another way:
I have a form that posts data. A var_dump($_POST) in the receiving code may produces for example this:
array(3) { ["item_273"]=> string(1) "1" ["item_107"]=> string(1) "5" ["item_65"]=> string(2) "10" }
As a result of this sample post I need to then have the following variables available in my receiving PHP code:
$item_16="1";
$item_273="5";
$item_65="10;
I will then loop through each item in the array, search the database for further information on each item such as say, price and weight:
$item_16_price="1.00";
$item_273_price="2.00";
$item_65_price="3.00";
and,
$item_16_weight="5";
$item_273_weight="10";
$item_65_weight="3";
and then total values to calculate total weight and total price:
$total_price=$item_16*$item_16_price;
$total_weight=$item_16*$item_16_weight;
to be able to build one results string:
$order="You have ordered:<br />";
$order.="Item: 16, Qty: 7, Weight: 5kg<br />";
$order.="Item: 273, Qty: 7, Weight: 5kg<br />";
$order.="Item: 65, Qty: 7, Weight: 5kg<br />";
$order.="Total Price: $41.00<br />";
$order.="Total Weight: 85kg<br />";
Using:
echo $order;
I can now produce the desired output:
You have ordered:
Item: 16, Qty: 7, Weight: 5kg
Item: 273, Qty: 7, Weight: 10kg
Item: 65, Qty: 7, Weight: 3kg
Total Price: $41.00
Total Weight: 53kg
I have supplied my "quasi" code again for your assistance.
//a) code here to set variables:
$item_16="1";
$item_273="5";
$item_65="10;
//b) code here to loop through the database picking up additional values for the three posted items like:
SELECT price,weight FROM PRODUCTS WHERE products_id={array value here}
$item_16_price="1.00";
$item_273_price="2.00";
$item_65_price="3.00";
$item_16_weight="5";
$item_273_weight="10";
$item_65_weight="3";
//c) looping finished and all variables set and available for use
$total_price=$item_16*$item_16_price;
$total_weight=$item_16*$item_16_weight;
//d) my outputing code for example that may calculate total weight and/or total price
//e) use all variables