Access array variable in session (CodeIgniter)

后端 未结 3 1404
攒了一身酷
攒了一身酷 2021-02-08 08:14

I have an array called config. I\'m trying to echo a variable from the array in the session.

I\'ve tried:

echo $this->session->userdata(\'config[\         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-08 08:52

    If you want to use the session array, use the variable, not the function:

    echo $this->session->userdata['user_data']['item'];
    

    If you want to write:

    $this->session->userdata['user_data']['item'] = 'value';
    $this->session->userdata['other_data']['other'] = 'value2';
    $this->session->sess_write();
    

    This allows you to edit values in array just like you do with $_SESION['user_data']['avatar'] = $avatar, with 'only' one extra line and only using CI library.

提交回复
热议问题