Session 会话::实例()并将数组数据推送到会话数组

Session 会话::实例()并将数组数据推送到会话数组,session,kohana,Session,Kohana,例如,我有Session::instance()->get('orders'),它是一些数组的数组: $first=数组('id'=1,'name'=>first','price'=>100); $second=数组('id'=>2,'name'=>'second','price'=>200); $\u SESSION['orders']=数组($first,$second) 但是如果我用这个 会话::实例()->set('orders',array(array('id'=>3,'name'=>

例如,我有Session::instance()->get('orders'),它是一些数组的数组:

$first=数组('id'=1,'name'=>first','price'=>100); $second=数组('id'=>2,'name'=>'second','price'=>200); $\u SESSION['orders']=数组($first,$second)

但是如果我用这个

会话::实例()->set('orders',array(array('id'=>3,'name'=>third','price'=>300))

这将删除第一批订单(id 1、id 2)。
那么,如何向名为“orders”的会话数组中添加但不删除数据数组呢?array\u push或其他什么?

编辑,没有看到您的评论,很完美

不言自明

$session = Session::instance();

// Find existing data
$data = $session->get('orders');

// Add new array
$data[] = array('id' => 3, 'name' => 'new data', 'price' => 300);

// Resave it
$session->set('orders', $data);

编辑,没有看到您的评论,非常完美

不言自明

$session = Session::instance();

// Find existing data
$data = $session->get('orders');

// Add new array
$data[] = array('id' => 3, 'name' => 'new data', 'price' => 300);

// Resave it
$session->set('orders', $data);

至于我,我认为最好的办法是:

public function before() {
...
$this->variable = Session::instance()->get('key', array());
...
}
一些代码

public function after() {
...
Session::instance()->set('key', $this->variable, Date::MINUTE);
...
}

至于我,我认为最好的办法是:

public function before() {
...
$this->variable = Session::instance()->get('key', array());
...
}
一些代码

public function after() {
...
Session::instance()->set('key', $this->variable, Date::MINUTE);
...
}

这是我的密码,好吗?这是我的密码,好吗?我还发现我们可以初始化$\u会话数组,并在原始php代码中使用它。我的意思是将SESSION::instance()链接到$\u会话数组,因为在kohana中,默认情况下我们不能直接使用$\u会话数组进行操作。我还发现我们可以初始化$\u会话数组,并在原始php代码中使用它。我的意思是链接SESSION::instance()由于在kohana中,默认情况下无法直接使用$\u会话数组进行操作,因此无法使用$\u会话数组。