Shopping Cart Purchase product operation

Source: Internet
Author: User

<?PHPSession_Start();//Add the fruit to your shopping cart .$code=$_get["Code"];//$_session["GWC"];if(Empty($_session["GWC"])){     //1. If it is the first time to click on the shopping cart, do a two-dimensional array thrown into the session     $attr=Array(        Array($code, 1)     ); $_session["GWC"] =$attr;}Else{      //determine if the fruit designator appears in the Sesson array      $attr=$_session["GWC"]; if(Panduan ($code,$attr))      {          //3. If it is not the first time you click Add to cart and the fruit is not the first click, add 1 to the number of the fruit in the Sesson array         /*foreach ($attr as $v) {if ($code = = $v [0]) {$v [1] = $v [1]+1; }          }*/           for($i= 0;$i<Count($attr);$i++)          {              if($code==$attr[$i][0])              {                  $attr[$i][1]++; }          }           $_session["GWC"] =$attr; }      Else      {          //2. If the first click is not added to the cart and the fruit is clicked for the first time, make an array of the fruit and throw it into the Sesson's two-dimensional array.          $arr=Array($code, 1); $attr[] =$arr; $_session["GWC"]=$attr; }}Var_dump($_session["GWC"]);//determine if V is present in ArrfunctionPanduan ($v,$arr){   $n= 0; foreach($arr  as $a)   {       if($v==$a[0])       {          $n++; }   }   if($n==0)   {       return false; }   Else   {       return true; }}
1. If it is the first time to click on the shopping cart, make a two-dimensional array thrown into the session 2. If it is not the first time you click Add to cart and the fruit is first clicked, make an array of that fruit into the Sesson's two-dimensional array inside 3. If it is not the first time you click Add to cart and the fruit is not the first click, add 1 to the number of the fruit in the Sesson array

After output

Shopping Cart Purchase product operation

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.