Skip to content

Instantly share code, notes, and snippets.

@aminnairi
Created January 18, 2022 18:46
Show Gist options
  • Save aminnairi/896a1220d07079ffe2468906dca425b1 to your computer and use it in GitHub Desktop.
Save aminnairi/896a1220d07079ffe2468906dca425b1 to your computer and use it in GitHub Desktop.
Exercice Fonction
<!DOCTYPE html>
<?php
$cart = [
[ "product" => "paper", "quantity" => 7, "price" => 1.26 ],
[ "product" => "pen", "quantity" => 2, "price" => 0.12 ],
[ "product" => "eraser", "quantity" => 5, "price" => 0.89 ]
];
$stocks = [
[
"product" => "paper",
"quantity" => 88
],
[
"product" => "handcleaner",
"quantity" => 0
],
[
"product" => "pen",
"quantity" => 34
],
[
"product" => "paperclip",
"quantity" => 11
],
[
"product" => "eraser",
"quantity" => 2
],
[
"product" => "letter",
"quantity" => 53
]
];
function getTotalPrice($product) {
return $product["quantity"] * $product["price"] . "$";
}
?>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="List of the products of our website.">
<title>Products</title>
</head>
<body>
<table>
<thead>
<tr>
<th>Produit</th>
<th>Quantité</th>
<th>Prix Unitaire</th>
<th>Prix Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($cart as $cartItem): ?>
<tr>
<td><?php echo $cartItem["product"]; ?></td>
<td><?php echo $cartItem["quantity"]; ?></td>
<td><?php echo $cartItem["price"]; ?></td>
<td><?php echo getTotalPrice($cartItem); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment