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

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:

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

Post 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,
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post 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]
Last edited by boo_lolly on Wed Jan 31, 2007 5:57 pm, edited 2 times in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Thank you, that worked fine.
Post Reply