1

How can I print a list of session arrays with php?

I have this php code:

foreach($wall as $v) 
    {
        $_SESSION['nickname'] = $v['user']['nickname'];
        $_SESSION['imageURL'] = $v['user']['imageURL'];
        $_SESSION['clubURL'] = $v['user']['clubURL'];
        $_SESSION['id'] = $v['id'];
        $_SESSION['date'] = $v['date'];
        $_SESSION['description'] = $v['description'];
        $_SESSION['byPhone'] = $v['byPhone'];
        $_SESSION['totalPage'] = $v['totalPage'];
        $_SESSION['userid'] = $v['user']['id'];
        $_SESSION['accountlikes'] = $v['account']['likes'] . ")";
        $_SESSION['accountdislikes'] = $v['account']['dislikes'] . ")";
        $_SESSION['accountcommentes'] = $v['account']['commentes'] . ")";
        $_SESSION['accountshares'] = $v['account']['shares'] . ")";
        $_SESSION['accountclicks'] = $v['account']['clicks'] . ")";
    }

And I want to print each value of each session variable.

3
  • Have you tried using a var_dump (php.net/manual/en/function.var-dump.php)? Commented Jun 7, 2011 at 22:05
  • 6
    You know you are overwriting every key of the session array with every iteration? Commented Jun 7, 2011 at 22:05
  • lol king actually didn't notice it +1 Commented Jun 7, 2011 at 22:07

3 Answers 3

3

As KingCrunch stated, you are overwriting every key of the session array with every iteration. I believe you meant for the code to look like this:

foreach($wall as $v) 
{
    $_SESSION['nickname'][] = $v['user']['nickname'];
    $_SESSION['imageURL'][] = $v['user']['imageURL'];
    $_SESSION['clubURL'][] = $v['user']['clubURL'];
    $_SESSION['id'][] = $v['id'];
    $_SESSION['date'][] = $v['date'];
    $_SESSION['description'][] = $v['description'];
    $_SESSION['byPhone'][] = $v['byPhone'];
    $_SESSION['totalPage'][] = $v['totalPage'];
    $_SESSION['userid'][] = $v['user']['id'];
    $_SESSION['accountlikes'][] = $v['account']['likes'] . ")";
    $_SESSION['accountdislikes'][] = $v['account']['dislikes'] . ")";
    $_SESSION['accountcommentes'][] = $v['account']['commentes'] . ")";
    $_SESSION['accountshares'][] = $v['account']['shares'] . ")";
    $_SESSION['accountclicks'][] = $v['account']['clicks'] . ")";
}

And to get a list of the $_SESSION array, use print_r($_SESSION); or var_dump($_SESSION);.

Sign up to request clarification or add additional context in comments.

Comments

3

I want to print each value of each session variable.

Just do:

print_r($_SESSION);

Comments

-1

Like this

echo "<pre>"; print_r($_SESSION); die;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.