Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3283238
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:01:04+00:00 2026-05-17T20:01:04+00:00

In PHP I often do the following: $_SESSION[‘var’][‘foo’] = array(‘bar1’ => 1, ‘bar2’ =>

  • 0

In PHP I often do the following:

$_SESSION['var']['foo'] = array('bar1' => 1, 'bar2' => 2);
// ...
$_SESSION['var']['foo']['bar2'] = 3;
// ...
echo $_SESSION['var']['foo']['bar2']; // 3

I’m wondering what the recommended way of storing multidimensional arrays in a session with Kohana.

I know I can do the following, but I don’t know how to make it work with multidimensional, specifically the get portion:

Session::instance()->set('var', array(
 'foo' => array(
  'bar1' => 1,
  'bar2' => 2,
 ),
));
// ...
// how do I set just bar2?
// ...
// this gets the whole array, but how do I get just bar2? 
Session::instance()->get('var');

So, the questions are:

  1. How do I set just bar2?
  2. How do I get just bar2?

Is there a way to do either of these in Kohana 3?

I’d love to use the native sessions, but we are trying to use database sessions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:01:05+00:00Added an answer on May 17, 2026 at 8:01 pm

    The short answer is that there is no way to do that, given the current implementation of Kohana sessions. You have two alternatives:

    Either get and set the entire array, editing the bits you need each time:

    $array = Session::instance()->get('var');
    $array['foo']['bar2'] = 'baz';
    Session::instance()->set('var', $array);
    

    Or you override the Kohana_Session->get() and ->set() methods (which are defined here on github).
    Keep in mind that, given the wonderful “layered” filesystem in Kohana, you can actually extend the class, modifying just the method you need, without editing the core Kohana code.

    My idea would be to change the $key parameter to accept either strings or arrays. If you pass in an array, it should interpret each element in the array as a “deeper” level.

    $key = array('var', 'foo', 'bar2');
    Session::instance()->get($key, $default);
    Session::instance()->set($key, 'baz');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have often used the following construct in Javascript: var foo = other_var ||
In php, I often need to map a variable using an array ... but
I am working on a PHP project. There, I often use following syntax to
I've seen the following often lately and I'm wondering what it does? I can't
PHP's explode function returns an array of strings split on some provided substring. It
PHP (among others) will execute the deepest function first, working its way out. For
In PHP when using the include function is the a way to tell from
Often I stumble upon following approach of defining conditional statement: if(false === $expr) {
I found the following code in php.ini . what does that mean? And PHP
Is something like the following possible in PHP? $blah = 'foo1'; class foo2 extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.