5. multiple conditions & arrays
solution 5.1<?php
$br = "\n";
$shippingPerKilo = 12; $shippingTax = 15; $productOne = ["name" => "t-shirt", "price" => 24.9, "tax" => 15, "weight" => 320]; $productTwo = ["name" => "hoodie", "price" => 46.24, "tax" => 15, "weight" => 510]; $productThree = ["name" => "jeans", "price" => 80.75, "tax" => 15, "weight" => 805]; $productFour = ["name" => "belt", "price" => 26.05, "tax" => 15, "weight" => 400];
$shipping = (($productOne["weight"] + $productTwo["weight"] + $productThree["weight"] + $productFour["weight"]) * $shippingPerKilo) / 1000;
$subtotal = $productOne["price"] + $productTwo["price"] + $productThree["price"] + $productFour["price"] + $shipping;
$tax = ($productOne["price"] $productOne["tax"]) / 100 + ($productTwo["price"] $productTwo["tax"]) / 100 + ($productThree["price"] $productThree["tax"]) / 100 + ($productFour["price"] $productFour["tax"]) / 100 + ($shipping * $shippingTax) / 100;
$total = $subtotal + $tax;
$receipt = $productOne["name"] . " $" . $productOne["price"] . $br . $productTwo["name"] . " $" . $productTwo["price"] . $br . $productThree["name"] . " $" . $productThree["price"] . $br . $productFour["name"] . " $" . $productFour["price"] . $br . "shipping $" . $shipping . $br . $br . "subtotal $" . $subtotal . $br . "tax $" . $tax . $br . "total $" . $total;
print_r($receipt);