• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
array session

Good day ma'am/sir, I dont see function in $this->session that can save/add value to a array saved session,

like this,


is there another way?

or just a make a plain PHP?

You can do the same in CI code, but you lose the added functionality of the Session library.
Using the Session library, keys for session properties have to be strings.

i made a helper, then i keep use the ci_session, just to save a session multi array

function set_userdata_array($data, $new_value)
$CI = &get_instance();
if (isset($_SESSION[$data]))
* to prevent same value
$unique_values = array();

foreach ($CI->session->userdata($data) as $value)
if (!in_array($value, $unique_values))//check if already one
$unique_values[] = $value; //get the usinque value

if (!in_array($new_value, $unique_values))//check if already one
$unique_values[] = $new_value; //now append the new value

$CI->session->set_userdata($data, $unique_values); //replaca the value with additional one
$CI->session->set_userdata($data, array($new_value)); //just create new one the initialize the value.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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