Jump to content

Can't Extract Array from Session Variable!


mmtalon

Recommended Posts

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#msg488542
http://www.phpfreaks.com/forums/index.php/topic,119312.0.html]
http://www.phpfreaks.com/forums/index.php/topic,119312.msg488542.html#msg488542
http://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 output
echo "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]
Link to comment
https://forums.phpfreaks.com/topic/33423-cant-extract-array-from-session-variable/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.