我创建了会话数组,我在那里放置了值,如下面的代码
$ar= array(
'product_id' => $this->input->post('productid'),
'qty'=> 1,
);
//creating products session array for the first time
$this->session->set_userdata('products',$ar);
现在,如何检索这些信息?我需要将新信息推送到现有会话数组。怎么做?
答案 0 :(得分:1)
只需获取它并以数组形式访问它:
$products = $this->session->userdata('products');
$id = $products['product_id'];
$qty = $products['qty'];
推动类似:
$products['new_info'] = 'something'; // provided you already fetched the array
$this->session->set_userdata('products', $products);
// now the 'products' session variable contains 'product_id', 'qty' and 'new_info'