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

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

like this,

$_SESSION[$key][]=$new_value;

is there another way?

or just a make a plain PHP?
Reply

#2
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.
Reply

#3
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
}
else
{
$CI->session->set_userdata($data, array($new_value)); //just create new one the initialize the value.
}
}
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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