Php shopping cart implementation code and application example

Source: Internet
Author: User
Php shopping cart implementation code and application example

  1. Class Shopcar
  2. {
  3. // Product list
  4. Public $ productList = array ();
  5. /**
  6. *
  7. * @ Param unknown_type $ the product to be imported
  8. * @ Return true no such item exists in the shopping cart
  9. */
  10. Public function checkProduct ($ product)
  11. {
  12. For ($ I = 0; $ I ProductList); $ I ++)
  13. {
  14. If ($ this-> productList [$ I] ['name'] = $ product ['name'])
  15. Return $ I;
  16. }
  17. Return-1;
  18. }
  19. // Add to shopping cart
  20. Public function add ($ product)
  21. {
  22. $ I = $ this-> checkProduct ($ product );
  23. If ($ I =-1)
  24. Array_push ($ this-> productList, $ product );
  25. Else
  26. $ This-> productList [$ I] ['num'] + = $ product ['num'];
  27. }
  28. // Delete
  29. Public function delete ($ product)
  30. {
  31. $ I = $ this-> checkProduct ($ product );
  32. If ($ I! =-1)
  33. Array_splice ($ this-> productList, $ I, 1 );
  34. }
  35. // Returns information about all products.
  36. Public function show ()
  37. {
  38. Return $ this-> productList;
  39. }
  40. }

22.16productlist.html

  1. Php shopping cart-item list page -bbs.it-home.org

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.