-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
42 lines (36 loc) · 892 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html>
<head>
<title>PHP Store</title>
</head>
<body>
<?php
// a comment
$name = "PHP Store";
$credit = 1000;
$products['computer'] = 750;
$products['car'] = 15000;
$products['phone'] = 500;
$products['toaster'] = 25;
$taxRate = 0.0825;
echo "<h1>Welcome to ".$name.".</h1>";
echo "<h2>You have $".$credit." in your wallet.</h2>";
foreach($products as $key => $value) {
$costWithTax = tax_calc($value, $taxRate);
echo "<p>The ".$key." costs $".$costWithTax."</p>";
}
echo "<h2>Items you can afford: </h2>";
foreach($products as $key => $value) {
$costWithTax = tax_calc($value, $taxRate);
if($costWithTax <= $credit) {
echo "<p>".$key."</p>";
}
}
function tax_calc($amount, $tax) {
$calculate_tax = $amount * $tax;
$amount = round($amount + $calculate_tax, 2);
return $amount;
}
?>
</body>
</html>