0

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.

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ok - I thought there may be a way without storing the array temporarily, Thankyou for the help - new it would be simple!
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.