Update quantity session array

Jakub Kotrady

I need a help

This is my session array:

Array
(
    [menu] => 
    [id] => 3
    [products] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name] => Produkt 1
                    [code] => 1
                    [varianta] => 
                    [pocet] => 1
                    [price] => 20
                    [pricepredtym] => 40
                )

            [1] => Array
                (
                    [id] => 2
                    [name] => Produkt 1
                    [code] => 1
                    [varianta] => 
                    [pocet] => 1
                    [price] => 20
                    [pricepredtym] => 40
                )

        )

)

I would need about something like, if ($_GET [id] == $ _SESSION ['products'] [id]) and only change this "[pocet]" where [id] = 2

$_GET [id] = 2; $pocet=5;

[1] => Array
                (
                    [id] => 2
                    [name] => Produkt 1
                    [code] => 1
                    [varianta] => 
                    [pocet] => 5
                    [price] => 20
                    [pricepredtym] => 40
                )
Bitwise Creative

You could index your products array by product id. Then updating would be simply:

if(isset($_SESSION['products'][$prod_id])) {
    $_SESSION['products'][$prod_id]['pocet'] = $pocet;
}

Otherwise, use a foreach loop:

foreach ($_SESSION['products'] as $i => $prod) {
    if ($prod['id'] == $prod_id) {
        $_SESSION['products'][$i]['pocet'] = $pocet;
        break;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Laravel 5 session array update

From Dev

Update value in session array php

From Dev

Quantity not updating in session

From Dev

update quantity with ajax

From Dev

How to update array with same key in Session Storage

From Dev

How to update session array via ajax?

From Dev

Checkbox with quantity field to array

From Dev

Query for update stock quantity in transaction

From Dev

How to update item quantity in excel?

From Dev

Dynamic Table Quantity update Javascript

From Dev

Use of "FOR UPDATE" during Magento stock quantity update

From Dev

how to update key of $_SESSION array with php variable value

From Dev

compare quantity of each item against quantity entered by user in form with array

From Dev

woocommerce - programmatically update cart item quantity

From Dev

How to Update Stock Quantity Manually in Magento

From Dev

update product quantity on check out page magento

From Dev

implementing quantity to update price of product and total price

From Dev

GET AND UPDATE Quantity in SQL using stored procedure

From Dev

Update quantity in MongoDB based on 2 conditions in PHP

From Dev

update product quantity on check out page magento

From Dev

Can MySQL update quantity field automatically?

From Dev

Laravel Cashier Quantity Increment Update Doesnt Work

From Dev

cannot update quantity in stock on database php/mysql

From Dev

Shopping cart's item will not update quantity

From Dev

How to increase product quantity if a product is already exist in session

From Dev

PHP session sum cart quantity even different product id

From Dev

Randomly select a specific quantity of indices from an array?

From Dev

How to sort an array with name, date and quantity? PHP

From Dev

autoit 2-D array count quantity

Related Related

  1. 1

    Laravel 5 session array update

  2. 2

    Update value in session array php

  3. 3

    Quantity not updating in session

  4. 4

    update quantity with ajax

  5. 5

    How to update array with same key in Session Storage

  6. 6

    How to update session array via ajax?

  7. 7

    Checkbox with quantity field to array

  8. 8

    Query for update stock quantity in transaction

  9. 9

    How to update item quantity in excel?

  10. 10

    Dynamic Table Quantity update Javascript

  11. 11

    Use of "FOR UPDATE" during Magento stock quantity update

  12. 12

    how to update key of $_SESSION array with php variable value

  13. 13

    compare quantity of each item against quantity entered by user in form with array

  14. 14

    woocommerce - programmatically update cart item quantity

  15. 15

    How to Update Stock Quantity Manually in Magento

  16. 16

    update product quantity on check out page magento

  17. 17

    implementing quantity to update price of product and total price

  18. 18

    GET AND UPDATE Quantity in SQL using stored procedure

  19. 19

    Update quantity in MongoDB based on 2 conditions in PHP

  20. 20

    update product quantity on check out page magento

  21. 21

    Can MySQL update quantity field automatically?

  22. 22

    Laravel Cashier Quantity Increment Update Doesnt Work

  23. 23

    cannot update quantity in stock on database php/mysql

  24. 24

    Shopping cart's item will not update quantity

  25. 25

    How to increase product quantity if a product is already exist in session

  26. 26

    PHP session sum cart quantity even different product id

  27. 27

    Randomly select a specific quantity of indices from an array?

  28. 28

    How to sort an array with name, date and quantity? PHP

  29. 29

    autoit 2-D array count quantity

HotTag

Archive