Php shopping cart implementation code and application example
- 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;
- }
- }
22.16productlist.html
-
- Php shopping cart-item list page -bbs.it-home.org
|