Php shopping cart implementation code _ php instance

Source: Internet
Author: User
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

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.