Page 1 of 1

Can

Posted: Fri Dec 15, 2006 8:36 am
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,

Posted: Fri Dec 15, 2006 8:42 am
by feyd
Try it.

And seriously, use FAR MORE descriptive thread titles please.

Posted: Fri Dec 15, 2006 8:48 am
by impulse()
That title wasn't intended.

Sorry either way.

Posted: Fri Dec 15, 2006 11:24 am
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"
    }
  }
}

Posted: Fri Dec 15, 2006 2:50 pm
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);
?>

Posted: Sun Dec 17, 2006 1:07 am
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.