Welcome Guest, Not a member yet? Register   Sign In
Updating a session array
#1

(This post was last modified: 10-19-2018, 01:26 PM by Qodi.)

I would like to update a session array using the codeigniter session library terminology.

I have a session array named chairs. Each key of the array is the chairID of the associated chair and the value of the chairID key is the quantity of chairs of with that ID.


I am looking at how I can update the array to add chairs to the array. 


I know the php syntax (bold). Below it is a list of possible codeigniter session library approaches I've postulated. They are probably all incorrect, I would appreciate some guidance.


$_SESSION['chairs'][$chairID] = $chairQuant;
               
$this->sesison->chairs[$chairID] = $chairQuant; (Simply replacing $_SESSION['chairs'] with $this->sesison->chairs)
               
$this->session->chairs += [$chairID => $chairQuant] (using unary array union operator)
                
{


$array = $this->session->chairs; 
               
array_push($array, array($chairID => $chairQuant))
               
$this->session->set_userdata(chairs, $array);


}  (Seemingly the most terminologically faithful approach, assign the session array value to another array, update this array using the array_push, then set the session array with the value of this new array. This approach feels very long winded, considering the alternative(s).)

Would appreciate help!

Thanks

God bless.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB