arjun sreekumar
arjun sreekumar

Reputation: 121

Can you store multiple arrays values in session?

I was planing to save the search inputs as arrays in session.

if ($this->input->post()) {
    $recent_search = array("Country" => $this->input->post('country'), 
                           "State" => $this->input->post('state'),
                           "Building" => $this->input->post('building'), 
                    );

I have saved the array in session as

$this->session->set_userdata('recentSearch',$recent_search);

The thing is after every form submission I'm taking in new array values. I want to store those input arrays into the session without erasing the old one. Is there any method that I could use?

Upvotes: 1

Views: 148

Answers (1)

Thrallix
Thrallix

Reputation: 731

I suggest you use localstorage or cookies rather than sessions.

Example:


$search_cache = [
   'Country' => $this->input->post('country'),
   'State' => $this->input->post('state'),
   'Building' => $this->input->post('building')
];

setcookie( 'recentSearch', $search_cache , time() + 3600 , '/');
var_export($_COOKIE);

Upvotes: 1

Related Questions