Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8623493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:17:40+00:00 2026-06-12T07:17:40+00:00

I want to implement the shopping cart by using multidimensional session array but don’t

  • 0

I want to implement the shopping cart by using multidimensional session array but don’t know how to access them. For example,

  • case1: user add one item to the cart with name “x” and size”m”. then add again with name “x” and size”m”

line1: pname”x” size”m” quantity”2″

  • case2: when user add one item to the cart with name “x” and size”m”. then the user add another item to the cart with name “x” but size”s”.

How can I manipulate it as 2 line of order?

line1: pname”x” size”m” quantity”1″
line2: pname”x” size”s” quantity”1″

     if (!isset($_SESSION['order'])) {
         $_SESSION['order'] = array();  
     }
     $_SESSION['order'][] = array('id'=>$pID, 'size'=>$size, 'quantity'=>0);

   switch ($action) {
    case "add":
        $_SESSION['order'][]['quantity']++;
    break;

    case "remove":
        unset($_SESSION['order'][][$pID]);
    break;

    case "empty":
        unset($_SESSSION['order']);
    break;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:17:41+00:00Added an answer on June 12, 2026 at 7:17 am

    Your session will get an element every time you call []. Add $pID as variable id:

    Change to:

    if (!isset($_SESSION['order'])) {
        $_SESSION['order'] = array();  
    }
    $_SESSION['order'][$pID.'-'.$size] = array('quantity'=>0);
    
    switch ($action) {
        case "add":
            $_SESSION['order'][$pID.'-'.$size]['quantity']++;
            break;
    
        case "remove":
            unset($_SESSION['order'][$pID.'-'.$size]);
            break;
    
        case "empty":
            // unset($_SESSION['cart']);
            unset($_SESSSION['order']);
            break;
    }
    

    You can later access that product with $_SESSION['order'][$pID.'-'.$size]

    To access them:

    foreach($_SESSION['order'] as $key => $one){
        list($pid, $size) = explode('-', $key);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a polyvore share button into a shopping cart. Some variable
I want to know, If I have a shopping(eg the cart..payment process) class and
I want to implement basic shopping cart functionality in my Rails app....are there any
I want implement in my software solution an VBA editor but in c# 3.0.
I want to implement login using facebook in my windows phone 7.1 application When
I want to add a block with a shopping cart summary in my website.
I want to power a very simple shopping-cart where I will be selling software.
I'm trying to implement PayPal on a completely custom shopping cart and have been
By default Codeigniter shopping cart class uses its built-in session functions. Session class in
I want to implement a shopping basket. I created a shopping basket class, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.