php - Retrieve information from session array in codeigniter


I have created session array and I have placed values there like the code below

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

            //creating products session array for the first time

Now, How to retrieve those information? and I need to push new information to existing session array. How to do that?




Simply fetch it and access it as an array:

$products = $this->session->userdata('products');

$id = $products['product_id'];
$qty = $products['qty'];

Pushing is similar:

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

People are also looking for solutions to the problem: bash - Executing script as daemon process in PHP


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.