Heimdall
3 months ago
281
2
General

Update session array

Posted 3 months ago by Heimdall

Hello,

I have a little problem :/ i want update my session array, but idk how

i have this : $productsessions = Session::get("products_session");

This return :


array:4 [
  0 => array:2 [
    "product_id" => 16
    "quantity" => 0
  ]
  1 => array:2 [
    "product_id" => 17
    "quantity" => 0
  ]
  2 => array:2 [
    "product_id" => 20
    "quantity" => 0
  ]
  3 => array:2 [
    "product_id" => 22
    "quantity" => 0
  ]
]

But on my controller i want for exemple update quantity when product_id = xx

i try this :


  foreach ($productsessions as $productsession) {
      if ($productsession['product_id'] == $product_id) {
          $productsession['quantity'] =  10;
      }
  }

but that dont work

Ty for your help

Please sign in or create an account to participate in this conversation.