Php shopping cart implementation code: This code is comprehensive. For more information, see. ShopCar. php
The Code is as follows:
Class Shopcar
{
// Product list
Public $ productList = array ();
/**
*
* @ Param unknown_type $ the product to be imported
* @ Return true no such item exists in the shopping cart
*/
Public function checkProduct ($ product)
{
For ($ I = 0; $ I ProductList); $ I ++)
{
If ($ this-> productList [$ I] ['name'] = $ product ['name'])
Return $ I;
}
Return-1;
}
// Add to shopping 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 );
}
// Returns information about all products.
Public function show ()
{
Return $ this-> productList;
}
}
ProductList.html
The Code is as follows:
Insert title here