Hello everyone,
I just started learning PHP about two months ago and I’m currently taking an online course and I’m having trouble with an assignment when I have to call a function multiple times. I have three products which I’m trying to add together for a grand total. When I call the function twice it works perfect. If I call it a third time it’s only outputting the third product.
I’ve been trying to figure this out for three days if anyone can help me I would really appreciate it, and if someone could also explain why this function is working this way as well.
Thank you,
Charlie
//Here is my code
Checkout
Below is a summary of the products you wish to purchase, along with totals:
- <?
- ”.$product.": $".$price;
productTotals($price, $tax, $shipping);
$grand_total = productTotals($price, $tax, $shipping);$product = “Coffee Table”;
$price = 99.50;
$shipping = 0.10; //shipping as a percentage of price
echo “ - ”.$product.": $".$price;
productTotals($price, $tax, $shipping);
$grand_total = productTotals($price, $tax, $shipping);$product = “Lamp”;
$price = 42.99;
$shipping = 0.10; //shipping as a percentage of price
echo “ - ”.$product.": $".$price;
productTotals($price, $tax, $shipping);
$grand_total = productTotals($price, $tax, $shipping);?>
$product = “Candle Holder”;
$price = 12.95;
$shipping = “”; //free shipping
echo “
Total (including tax and shipping): $<? echo number_format($grand_total, 2); ?> .