Pooja Krishna
Pooja Krishna

Reputation: 293

Update session array variable in codeigniter

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.....

Upvotes: 1

Views: 6414

Answers (2)

Razib Al Mamun
Razib Al Mamun

Reputation: 2711

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);

Upvotes: 1

safin chacko
safin chacko

Reputation: 1390

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);  

Upvotes: 4

Related Questions