Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ArchStanton's avatar

adding key/value pair to a session

So my session stores an array

dd(Session::get('order) );
array (size=17)
  'APIKey' => string 'xxxxx' (length=36)
  'SiteID' => string 'xxxx' (length=36)
  'UserID' => string 'xxxxx' (length=36)

I want to add another key/value pair to this session

array (size=17)
  'APIKey' => string 'xxxxx' (length=36)
  'SiteID' => string 'xxxx' (length=36)
  'UserID' => string 'xxxxx' (length=36)
   'newone' => string 'look I added a new key' (length=36)
0 likes
2 replies
RobinMalfait's avatar
Level 7

You can do something like this

$order = Session::get('order');

$order['newone'] = 'look I added a new key';

Session::put('order', $order);
unitedworx's avatar

I would give this a try as well!!

Session::put('order.newone', 'look I added a new key');

Please or to participate in this conversation.