How can PHP be used to calculate totals in an online order form?
To calculate totals in an online order form using PHP, you can create variables to store the prices of each item selected by the user. Then, you can use arithmetic operations to calculate the subtotal, tax, and total amount of the order. Finally, you can display the calculated totals to the user on the order form.
<?php
// Prices of items selected by the user
$item1_price = 10.99;
$item2_price = 15.99;
// Calculate subtotal
$subtotal = $item1_price + $item2_price;
// Calculate tax (assuming 8% tax rate)
$tax_rate = 0.08;
$tax = $subtotal * $tax_rate;
// Calculate total amount
$total = $subtotal + $tax;
// Display totals to the user
echo "Subtotal: $" . number_format($subtotal, 2) . "<br>";
echo "Tax: $" . number_format($tax, 2) . "<br>";
echo "Total: $" . number_format($total, 2);
?>