Home > Backend Development > PHP Tutorial > php shopping cart php shopping cart implementation code

php shopping cart php shopping cart implementation code

WBOY
Release: 2016-07-29 08:46:55
Original
2098 people have browsed it

ShopCar.php

Copy the code The code is as follows:


class Shopcar
{
//Product list
public $productList=array();
/**
*
* @param unknown_type $product The product passed in
* @return true The product is not in the shopping cart
*/
public function checkProduct($product)
{
for($i=0;$iproductList);$i++ )
{
if($this->productList[$i][' name']==$product['name'])
return $i;
}
return -1;
}
//Add to cart
public function add($product)
{
$i=$this ->checkProduct($product);
if($i==-1)
array_push($this->productList,$product);
else
$this->productList[$i]['num' ]+=$product['num'];
}
//Delete
public function delete($product)
{
$i=$this->checkProduct($product);
if($i!=- 1)
array_splice($this->productList,$i,1);
}
//Return all product information
public function show()
{
return $this->productList;
}
}


productList.html

Copy code The code is as follows:













Product numberProduct namePriceQuantityBuy
0
Item 2
Item 3
Item 4
' />



The above introduces the php shopping cart php shopping cart implementation code, including the content of php shopping cart. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template