Qualcuno mi può aiutare?
Come posso raccogliere in una funzione il codice ripetitivo e portarlo fuori dal programma qui sotto?
Checkout
Below is a summary of the products you wish to purchase, along with totals:
<?php
#tax rate is constant
$tax = 0.08;
?>
<ul>
<?php
function CH($price, $tax, $shipping){
$total_price += $price;
$total_tax += $tax * $price;
$total_shipping += $shipping * $price;
$total= ($total_price + $total_tax + $total_shipping);
$product = "Candle Holder";
$price = 12.95;
$shipping = 0;
echo "[*]" .$product.": $".$price."
";
return $total;
}
$CH = CH(12.95, 0.08, 0); //
echo "Sub-totals = $" .$CH."
";
?>
<?php
function CT($price, $tax, $shipping){
$total_price += $price;
$total_tax += $tax * $price;
$total_shipping += $shipping * $price;
$total = ($total_price + $total_tax + $total_shipping);
$product = "Coffee Table";
$price = 99.50;
$shipping = 0.01;
echo "[*]" .$product.": $".$price."
";
return $total;
}
$CT = CT(99.50, 0.08, 0.1); //
echo "Sub-total = $" .$CT."
";
?>
<?php
$grand_total = ($CH + $CT);
?>
[B]TOTAL : $<? echo number_format($grand_total, 2);?>[B]