如何在codeigniter中将数组保存到会话中?

I want to save an array in codeigniters' session helper but I keep getting

I want to save an array of arrays in a new session variable so that I can view that session in another controller if I need it or in another view.

my session is autoloaded in my config file.

this piece of code is in my view file. $arr = array();

foreach($value->result as $val){}
    if($val->somethinghappenedtrue){
        $arr[] = array('data' => $thethingthathappened);
    }
}
// since my session is autoloaded I don't need to initialize
//session if I'm not wrong $this->load->session etc...
$this->session->new_session_name($arr);

Fatal error: Call to undefined method CI_Session::new_session_name()

Let’s say a particular user logs into your site. Once authenticated, you could add their username and e-mail address to the session, making that data globally available to you without having to run a database query when you need it.

You can simply assign data to the $_SESSION array, as with any other variable. Or as a property of $this->session.

Alternatively, the old method of assigning it as “userdata” is also available. That however passing an array containing your new data to the set_userdata() method:

$this->session->set_userdata($array);

Your code should be

foreach($value->result as $val){}
    if($val->somethinghappenedtrue){
        $arr[] = array('data' => $thethingthathappened);
    }
}
// since my session is autoloaded I don't need to initialize
//session if I'm not wrong $this->load->session etc...
$this->session->set_userdata($arr);

If you want to add userdata one value at a time, set_userdata() also supports this syntax:

$this->session->set_userdata('some_name', 'some_value');

If you want to verify that a session value exists, simply check with isset():

// returns FALSE if the 'some_name' item doesn't exist or is NULL, // TRUE otherwise:

isset($_SESSION['some_name'])