/    Sign up×
Community /Pin to ProfileBookmark

Easy ? on the $_SESSION array

I’ve been looking at the docs for quite some time but I can’t find a simple answer to my simple problem.

I have a bunch of values for in the $_SESSION array. I’ve found foreach and I can print (or do whatever) each value. How can I find the key name?

For example, I have $_SESSION[name]=”Bob” and $_SESSION[phone]=555. I want to be able to do something like…

foreach($_SESSION as $tempval) {
echo “His ” . $key . ” is ” . $tempval . “<br>”;
}

and have in result in…

His name is Bob
His phone is 555

My goal is to ultimately create JavaScript functions for each $_SESSION value, but I want to extract the key and the key’s value.

Can anyone help me out? Thanks!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ScleppelSep 12.2005 — You have to have it as foreach($array as $key => $val)...
[code=php]
foreach($_SESSION as $key => $tempval) {
[/code]
Copy linkTweet thisAlerts:
@leadedauthorSep 13.2005 — Thanks!!!
×

Success!

Help @leaded spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...