Home  >  Article  >  Backend Development  >  Example analysis of preliminary implementation of shopping cart function in php

Example analysis of preliminary implementation of shopping cart function in php

黄舟
黄舟Original
2017-08-18 17:18:251285browse

In our daily development work, we often develop malls and shopping websites. Since it is a shopping website, the shopping cart function is indispensable. This function is very complicated. The nature is quite big, so what we introduce to you today is an example of preliminary completion of the shopping cart!

The first step is to download the preliminary implementation of the PHP shopping cart class library we need to use in this course: http://www.php.cn/xiazai/leiku/339

Second step, after the download is completed, find the php class file we need, unzip it to our local directory, and create a new php file!

The third step, after completion, we need to call this class in the new php file and instantiate the class:

<?php
include_once "cart.php";//引入类文件
$cart = Cart::Getcat(); //实例化

$cart->Additem(&#39;1&#39;, &#39;手机&#39;, 31, 1);
$cart->Additem(&#39;2&#39;, &#39;电源&#39;, 21, 1);
$cart->Additem(&#39;3&#39;, &#39;显示器&#39;, 11, 10);
echo "<pre class="brush:php;toolbar:false">";
print_r($cart);

$cart->Reduceitem(2,10);
print_r($cart);

echo "总价:".$cart->Getprice()."<br>";
echo "数量:".$cart->Getnumber();
?>

Run this file and get the result as shown below:

Example analysis of preliminary implementation of shopping cart function in php

Note:

We have initially completed the shopping cart function here, for backup

The above is the detailed content of Example analysis of preliminary implementation of shopping cart function in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn