Can

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Can

Post by impulse() »

$_SESSION be a 2-D array?

For example:

Code: Select all

$_SESSION["board"][$i] = 2;
I'm sceptical at the moment as it's not containing a value once assigned.

Regards,
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Try it.

And seriously, use FAR MORE descriptive thread titles please.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

That title wasn't intended.

Sorry either way.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

I have never tried that with session. So, here goes the test :

Code: Select all

<?php
session_start();
$_SESSION[x][y][z] = 'xyz';
$_SESSION[a][b][c] = 'abc';

var_dump($_SESSION);
?>
Output :

Code: Select all

array(2) {
  ["x"]=>
  array(1) {
    ["y"]=>
    array(1) {
      ["z"]=>
      string(3) "xyz"
    }
  }
  ["a"]=>
  array(1) {
    ["b"]=>
    array(1) {
      ["c"]=>
      string(3) "abc"
    }
  }
}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

But for freaking crying out loud wrap your array indexes in quotes... :wink:

I like feyd's advice. Try it. Seriously, What is the worst that could happen? But for clean coding sake, this:

Code: Select all

<?php
session_start();
$_SESSION[x][y][z] = 'xyz';
$_SESSION[a][b][c] = 'abc';

var_dump($_SESSION);
?>
should be:

Code: Select all

<?php
session_start();
$_SESSION['x']['y']['z'] = 'xyz';
$_SESSION['a']['b']['c'] = 'abc';

var_dump($_SESSION);
?>
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Thanks Everah for commenting. Yes I forgot to put quotes.

Output :

Code: Select all

array(2) {
  ["x"]=>
  array(1) {
    ["y"]=>
    array(1) {
      ["z"]=>
      string(3) "xyz"
    }
  }
  ["a"]=>
  array(1) {
    ["b"]=>
    array(1) {
      ["c"]=>
      string(3) "abc"
    }
  }
}
Thank you.
Post Reply