• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding values to an existing Session array

I am creating a session array called "entry_data" and filling it with a few values, like this:
$entry_data = array(
    'album_title' => $this->input->post('album_title'),
    'release_date' => $this->input->post('release_date')
$this->db_session->set_userdata('entry_data', $entry_data);

How do I go about later adding more values to the $entry_data session array without overwriting the data that's already there?


I don't know if there is better way, but you can retrieve 'entry_data' array from session, alter it, and store it again in session (with the same name).


Hey there. Array() is typically used to create a new array. Thereafter, you can use:

$entry_data['newkey'] = "newdata";

This will add new data without removing the rest of your data. If you would like to add data to the end of the array, without having a specific key, you can use:

$entry_data[] = "newdata";

I would highly suggest reading:


Awesome. Thank you!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.