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 9219407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:06:40+00:00 2026-06-18T03:06:40+00:00

First I added a session then I print my session it looks completely ok

  • 0

First I added a session then I print my session it looks completely ok here it is

Array
(
[14] => Array//(main key is my restaurant Id)
    (
        [retaurantDetail] => Array
            (
                [restId] => 14
                [restaurantName] => Barca
                [published] => 1
                [timings] => 10 to 10
                [normalCost] => 150
                [logo] => 44f7afcffb0aeea5c69ccee9041cab84.jpg
                [email] => barca@barca.com
                [phone] => 741258
            )

        [menuArray] => Array
            (
                [70] => Array // (menu ID is the Key)
                    (
                        [menuId] => 70
                        [productId] => 35
                        [productName] => Coca Cola
                        [categoryTitle] => Beverages
                        [categoryId] => 52
                        [price] => 100
                        [attributeName] => 1.5L
                        [isDefault] => 1
                        [qty] => 1
                    )

            )

    )
)

Now I add some logic if some one add again that menu in add to cart in short he/she adds plus 1 qty to that menu here it is my code,(code is not completed yet but now I am focused on just to update qty)

            foreach($session->cartSession as $sessionKey=>$sessionVal)
            {

                        foreach($sessionVal['menuArray'] as $sessionMenuKey=>$sessionMenuVal)
                        {

                            if($sessionMenuKey == $post_data['menuId'])
                            {
                                echo"<pre>"; print_r($sessionMenuVal['qty']); echo "</pre>";
                                //$qty = $session->cartSession[$restaurantDetail['restId']]['menuArray'][$sessionMenuKey];
                                $sessionMenuVal['qty'] =  $sessionMenuVal['qty']+1;

                                echo"<pre>"; print_r($sessionMenuVal['qty']); echo "</pre>"; 

                            }

                         }
            }

What I am missing I want to updatre session qty.

every time I press add it shows 1 qty then I add plus 1 qty to it then it show 2 after then it again shows 1 qty :(.

  • 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-18T03:06:41+00:00Added an answer on June 18, 2026 at 3:06 am

    You’re never writing back into the Session…

    If i understand your code correctly, the following should work. Check the correct Array-Nesting of my code in case it doesn’t work out of the box.

    // Somewhere on top, use this for your loops
    $cartSession = $session->offsetGet('cartSession'); 
    
    // Inside your matched loop
    $currentQty = $sessionMenuVal['qty'];
    $cartSession[$sessionKey][$sessionMenuKey]['qty'] = ++$currentQty;
    
    // After your loops at the end
    $session->offsetSet('cartSession', $cartSession);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've added my first OneToMany relationship to my hibernate 3.6.10 project. Here is the
Documentation says Dictionary keys order is unspecified. I guess it means the first added
I have added one view controller to my first view controller as aa subview
I edited epoc.ini added textshell in the first line. When I run from the
I'm developing my first Word 2007 addin, and I've added an OfficeRibbon to my
I have a table. Some rows are dynamically added by jquery. The first <td>
Totally n00b question, Im making my first ASP.NET website, with the added twist of
First time post here, I hope its a valid question. I've been building a
What's wrong here? res.render('/somepage', {user:req.session.user}) It leads to Converting circular structure to JSON errors,
working with pre existing code just a simple patch i added ontop //first get

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.