Reputation: 1024
Hi all I'm using CI and I have set an array using the CI built in methods as seen below:
$arrayBools = array();
for($y = 0; $y < 30; $y++){
$arrayBools[$y] = false;
}
$this->session->set_userdata('arrayBools', $arrayBools);
this works and sets the array in the session variable without an issue - however i am confused if I only want to change a single element in the array to true - could someone point me in the right direction - apologies if simple complete beginner to all of this.
Upvotes: 0
Views: 1792
Reputation: 80
I think CodeIgniter doesn't allow to do that.
You have no other choice that get all your array :
$data = $this->session->userdata('arrayBools');
then after editing your data to set all the array
$this->session->set_userdata('arrayBools',$data);
It's not possible to access only on item of an array set in session.
Upvotes: 1
Reputation: 4812
it's actually fairly simple: you just retrieve the array, modify the value, write it back to session
$arr = $this->session->userdata('arrayBools');
$arr[3] = false;
$this->session->set_userdata('arrayBools',$arr);
there ya go.
Upvotes: 4