i have the code below where i am trying to traverse a two dimensional array using list() and each(). i was wondering if anyone can help. i am getting 3 warnings:
Warning: Variable passed to each() is not an array or object in ... line 44
output is as follows:
Checkout
Below is a summary of the products you wish to purchase, along with totals:
Warning: Variable passed to each() is not an array or object in /users/../useractivepreviewtmp284.php3 on line 44
Warning: Variable passed to each() is not an array or object in /users/../useractivepreviewtmp284.php3 on line 44
Warning: Variable passed to each() is not an array or object in /users/../useractivepreviewtmp284.php3 on line 44
Total (including tax and shipping): $0.00
Code is as follows:
<B>Checkout</B><br>
Below is a summary of the products you wish to purchase, along with totals:
<?php
$total_price = 0;
$total_tax = 0;
$total_shipping = 0;
$grand_total = 0;
?><ul><?
//2 dimensional array that acts as a DB and stores Name, Price and Shipping (as a % of price) for every given item,
$product = array( array(Name => "Candle Holder",
Price => 12.95,
Shipping => 0.0 //free shipping
),
array(Name => "Coffee Table",
Price => 99.50,
Shipping => 0.10 //shipping as a % of price
),
array(Name => "Lamp",
Price => 42.99,
Shipping => 0.10 //shipping as a % of price
));
for($row = 0; $row < count($product[$row]); $row++ )
{
while (list($key, $val) = each($products[ $row ] ))
{
echo "$key => $val\n";
}
}
/*
Purpose: function CALCulates a total (incl. tax) price payable by the consumer a given item
INPUT: price and shiping for each item
OUTPUT: total price which includes tax
*/
function calc_total($price, $shipping)
{
#tax rate is constant
$tax = 0.08;
$total_price += $price;
$total_tax += $tax * $price;
$total_shipping += $shipping * $price;
$grand_total = ($total_price + $total_tax + $total_shipping);
return $grand_total;
}
?>
</ul>
<hr>
<br>
<B>Total (including tax and shipping): $<? echo number_format($grand_total, 2); ?></B>