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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.