CMartins
CMartins

Reputation: 3293

PHP Session Array list

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.

Upvotes: 1

Views: 6683

Answers (3)

Rana Aalamgeer
Rana Aalamgeer

Reputation: 712

Like this

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

Upvotes: -1

John M.
John M.

Reputation: 2264

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);.

Upvotes: 3

Sarfraz
Sarfraz

Reputation: 382616

I want to print each value of each session variable.

Just do:

print_r($_SESSION);

Upvotes: 3

Related Questions