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

#1
[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!

#2
[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).

#3
[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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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