Array in sessions

How change array in session? example $_SESSION['var']['var2'] = 1;


Zach, u can show example?

edited Jul '15

Phalcon's built-in session handler only allows you to do key/value setting - not deep setting inside an array.

@stanleer - did you try what you exampled? That should work, provided you've actually set $_SESSION["var"] and $_SESSION["var"]["var2"]


I store nested, mluti-dimensional arrays in session:

Inside of a model:

    public function doSomething() {
        $array = [
            "value1" => "Awesome",
            "value2" => "Heay, neat",
            "nested1" => [
                "nestedvalue1" => "Super!",
                "nestedvalue2" => "Excellent"
        $this->getDi()->getShared('session')->set('sessionval', $array);
        return true;

Inside of a controller, you can set by:


Retrieve by calling:

    $this->session->get('sessionval'); //in a controller
    $this->getDi()->getShared('session')->get('sessionval'); //in a model


To further answer your question...

Get the session array:

    $sessionVal = $this->session->get('sessionval');

Then do what you need to do with the array:

    $sessionVal['nested1']['nestedvalue1'] = "Super duper!";

Then store the value: