Crusader Posted April 23, 2007 Share Posted April 23, 2007 This is my 2D array: $sectors = array ( 'x' => $map['x'], 'y' => $map['y'], 'link'=> $game->makeLink( ); Will the following foreach call generate sessions for the above array? I don't have any way to test it right now /** * Generate sessions for coordinate arrays. */ function mapLinks() { foreach($this->sectors as $k => $v) { $sess = $this->sectors[$k]['link']; $_SESSION[$sess] = array ( "x" => $this->sectors[$k]['x'], "y" => $this->sectors[$k]['y'] ); } } Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/48258-foreach-and-2d-arrays/ Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 to output an array <?php print_r($sectors); ?> or <?php print_r($$_SESSION); ?> Quote Link to comment https://forums.phpfreaks.com/topic/48258-foreach-and-2d-arrays/#findComment-235886 Share on other sites More sharing options...
Crusader Posted April 23, 2007 Author Share Posted April 23, 2007 Thanks but I know how to output arrays. I actually want to store the arrays in a session. note: $map is an array as well. it's a mysql_fetch_array It should output like this: $_session(14u01jr0af0m2) = array (x => 1, y =>3); $_session(10rm0WFG02af) = array (x => 3, y =>5); Quote Link to comment https://forums.phpfreaks.com/topic/48258-foreach-and-2d-arrays/#findComment-235891 Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 and whats wrong with the way your doing it ? Quote Link to comment https://forums.phpfreaks.com/topic/48258-foreach-and-2d-arrays/#findComment-235897 Share on other sites More sharing options...
Crusader Posted April 23, 2007 Author Share Posted April 23, 2007 and whats wrong with the way your doing it ? I'm not able to test it at the moment and I was hoping there was a simpler way to do it... Quote Link to comment https://forums.phpfreaks.com/topic/48258-foreach-and-2d-arrays/#findComment-235904 Share on other sites More sharing options...
kenrbnsn Posted April 23, 2007 Share Posted April 23, 2007 The easiest way to store the array in a session, is to store the whole array in the sessions: <?php session_start(); $sectors = array ( 'x' => $map['x'], 'y' => $map['y'], 'link'=> $game->makeLink( ); $_SESSION['sectors'] = $sectors; ?> The you retrieve it with: <?php session_start(); $sectors = $_SESSION['sectors']; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/48258-foreach-and-2d-arrays/#findComment-235949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.