PHP develops simple shopping cart shopping cart page
cart.php This page displays the products, price, quantity, total price and other information in the shopping cart.
Continue to enable the session, take out various information in the product from the session and display it
The foreach loop output is used here.
You can return to the product display page to continue purchasing
<html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>PHP购物车页面</title> </head> <body> <?php session_start(); //将session中的商品信息(即购物车中的商品)和总价显示到页面 $goods = $_SESSION['goods']; echo '您购买的商品:<br /><br />'; foreach ($goods as $value) { echo '商品名称:' . " " . $value['name'] . ' ' . ' 价格: ' . " " . $value['price'] . ' ' . ' 数量: ' . $value['number'] . '<br /><br />'; } echo '总价:' . $_SESSION['totalPrice'] . '<br /><br />'; ?> <a href="list.php">返回商品列表</a> </body> </html>
Such a simple shopping cart function is completed, friends can try it by themselves.
This tutorial is only suitable for friends to learn and reference, and cannot be used for actual projects.