mmtalon Posted January 9, 2007 Share Posted January 9, 2007 I read the two mulitdimensional post below, however I could not draw a conclusion from them.[url=http://www.phpfreaks.com/forums/index.php/topic,119312.msg488542.html#msg488542http://www.phpfreaks.com/forums/index.php/topic,119312.0.html]http://www.phpfreaks.com/forums/index.php/topic,119312.msg488542.html#msg488542http://www.phpfreaks.com/forums/index.php/topic,119312.0.html[/url]I varified that the array is being stored properly by a session dump:[code]foreach ( $_SESSION as $key => $key_value ) { print "<li> $key = $key_value\n"; }[/code]dump result: X = Array - Where X is the name of my array($count).An example of my code is below. I tried to retrieving the array using the two foreach construct below. I must be doing something wrong. Please help.[code] session_start();$_SESSION['count']; // tried session var init here$_SESSION['count'] = array(); // tried session array init here$v[0] = 489; $v[1] = 883; $v[2]= 350; $v[3] = 555;for ($counter=0; $counter < 4; $counter++){ $count[$counter] = $v[$counter]; }// this code result in successful outputecho "count_0: " . $count[0];echo "<p>count_1: $count[1]\n\r</p>";echo "<p>count_2: $count[2]\n\r</p>";echo "<p>count_3: $count[3]\n\r</p>";$trans = $_SESSION['count'];// no extraction results from the following code:foreach ($trans[] as $key => $value ) { echo "<p> $key = $value\n</p>"; }foreach($_SESSION['count'][] as $var) {echo "this is a new count:". $var;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/ Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 foreach($_SESSION['count'] as $var) {echo "this is a new count:". $var;}Try taking off that second [] Quote Link to comment https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/#findComment-156431 Share on other sites More sharing options...
mmtalon Posted January 9, 2007 Author Share Posted January 9, 2007 Still not working with that change. I'm looking for other examples now. Quote Link to comment https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/#findComment-156440 Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Wait you never actually put anything in the session. before this:[code]foreach($_SESSION['count'] as $var) { echo "this is a new count:". $var;}[/code]you need to do something like $_SESSION['count'] = $count.That's why $_SESSION['count'] is empty. Quote Link to comment https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/#findComment-156443 Share on other sites More sharing options...
mmtalon Posted January 9, 2007 Author Share Posted January 9, 2007 Thank you. I'm taking a look at that right now. Quote Link to comment https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/#findComment-156460 Share on other sites More sharing options...
mmtalon Posted January 9, 2007 Author Share Posted January 9, 2007 I thought this code was initializing the array:for ($counter=0; $counter < 4; $counter++){ $count[$counter] = $v[$counter]; } Quote Link to comment https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/#findComment-156463 Share on other sites More sharing options...
mmtalon Posted January 9, 2007 Author Share Posted January 9, 2007 I thought wrong. The code worked after using your suggestion. Thank you jesirose so much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/#findComment-156471 Share on other sites More sharing options...
mmtalon Posted January 9, 2007 Author Share Posted January 9, 2007 To clarify, I thought that the array was a reference of the session variable when you create the session using the name of the particular variable. So I really learned something from you that is important to know. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/#findComment-156477 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.