php - Codeigniter add new item to current session userdata array -
so have array:
$data = array( 'item_1' => $this->input->post('item_1'), 'item_2' => $this->input->post('item_2'), 'item_3' => $this->input->post('item_3') ); $this->session->set_userdata( 'items', $data );
and want add new item array, updated array of userdata this:
$data = array( 'item_1' => $this->input->post('item_1'), 'item_2' => $this->input->post('item_2'), 'item_3' => $this->input->post('item_3'), 'item_4' => $this->input->post('item_4') ); $this->session->set_userdata( 'items', $data );
how that, thank you
follow these steps add data current session:
$data = $this->session->userdata('items'); $data['item_4'] = $this->input->post('item_4'); $this->session->set_userdata('items', $data);
here, first take out current session items
in array, add item array, can array_push()
prefer above. now, set session updated data.
Comments
Post a Comment