CodeIgniter Forums
Adding values to an existing Session array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Adding values to an existing Session array (/showthread.php?tid=4034)



Adding values to an existing Session array - El Forum - 11-03-2007

[eluser]BrandonDurham[/eluser]
I am creating a session array called "entry_data" and filling it with a few values, like this:
Code:
$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?

Thanks!


Adding values to an existing Session array - El Forum - 11-03-2007

[eluser]mironcho[/eluser]
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).


Adding values to an existing Session array - El Forum - 11-03-2007

[eluser]Pygon[/eluser]
Brandon:

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:

http://www.w3schools.com/php/php_arrays.asp


Adding values to an existing Session array - El Forum - 11-03-2007

[eluser]BrandonDurham[/eluser]
Awesome. Thank you!