Page 1 of 1

Is it possible to var_dump or print_r a 3D SESSION array?

Posted: Wed Jan 31, 2007 9:40 am
by impulse()
Afternoon, I have a 3D session array and I can only view the values of individual keys if I echo them manually. I have the following code:

Code: Select all

session_start();
$_SESSION[1]["test1"] = "sesh 1 test1";
$_SESSION[1]["test2"] = "sesh 1 test2";
$_SESSION[2]["test1"] = "sesh 2 test1";

var_dump($_SESSION);      //
print_r($_SESSION);           //
var_dump($_SESSION[1]);  // 
print_r($_SESSION[1]);       // -- All these show items within a 2D sense of $_SESSION
var_dump($_SESSION[2]);  //
print_r($_SESSION[2]);       //

echo $_SESSION[1]["test1"]; // Works
But this is only showing the array in a 2D sense.

Any ideas as to how I see every container within the array?

Regards,

Posted: Wed Jan 31, 2007 10:19 am
by boo_lolly
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


actually, it looks to me like you have a 2-dimensional associative array. to list the contents of a 2-dimensional array:

Code: Select all

<?php
	for($row = 0; $row < $numofkeys; $row++){
		while(list($key, $val) = each($_SESSION[$row])){
			echo "|". $val ."";
		}
      echo "<br />\n";
	}
?>
for a 3-dimensional array:

Code: Select all

<?php
	for($layer = 0; $layer < $numofkeys; $layer++){
		echo "Layer ". $layer ."<br />\n";
		for($row = 0; $row < $numofkeys2; $row++){
			for($column = 0; $column < $numofcolumns; $column++){
				echo "|". $array[$layer][$row][$column];
			}
			echo "<br />\n";
		}
	}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jan 31, 2007 10:19 am
by pickle

Posted: Wed Jan 31, 2007 11:17 am
by impulse()
Thank you, that worked fine.