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;$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;
}
}
Copy code The code is as follows:
Product number | Product name | Price | Quantity td> | Buy | |||||||||
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.