1

I am suck with an issue.

I have a session array which i need to update. Don't know how to update it.

$detailsData    =   $this->session->userdata['detailsData']['tot_amt'];

I need to update the value of 'tot_amt'.How to implement this?

Waiting for response.....

2
  • show you full session arrray Commented Nov 18, 2016 at 13:47
  • what is your session variable ? Commented Nov 18, 2016 at 13:48

2 Answers 2

4

If 'detailsData' is the session variable and has an array in it. Then

$detailsData    =   $this->session->userdata('detailsData');
$detailsData['tot_amt']= "Any Value";
$this->session->set_userdata('detailsData', $detailsData);  
Sign up to request clarification or add additional context in comments.

1 Comment

It's bad if you're using it with any event driven or async function and you're checking and updating session in more than one places. It will cause error.
1

For update session value like this :

// modify session
$this->session->set_userdata('tot_amt', 'New value');

when you need to replace old data just unset previous data and then set again your new data

Example :

$session_data = array('uid' => 'test user', 'logged_in' => TRUE);
$this->session->set_userdata($session_data);

//remove old data
$this->session->unset_userdata($session_data);

// modify session
$session_data = array('uid' => 'New user', 'logged_in' => TRUE);
$this->session->set_userdata($session_data);

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.