簡體   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