繁体   English   中英

从Codeigniter中的会话数组中检索信息

[英]Retrieve information from session array in codeigniter

我创建了会话数组,并在其中放置了值,如下面的代码

$ar= array(
            'product_id' => $this->input->post('productid'),
            'qty'=> 1,

            );
            //creating products session array for the first time
            $this->session->set_userdata('products',$ar);

现在,如何检索这些信息? 我需要将新信息推送到现有会话数组。 怎么做?

只需获取它并将其作为数组访问即可:

$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'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM