0

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
            $this->session->set_userdata('products',$ar);

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

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.