/    Sign up×
Community /Pin to ProfileBookmark

Hi Im new to php and trying to get an understanding of some of the syntax –
I was hoping that someone could explain the following bits of code and what it does

if (isset($_SESSION[‘somesession’][$somevariable])) {
$items = $_
SESSION[‘somesession’][$somevariable]; }

I understand the isset method but I dont understand what this is supposed to do

$_SESSION[‘somesession’][$somevariable]

is it a concatenation or merge of somesort –

any help would be greatly appreciated.

Thanks

Tim

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 03.2012 — It specifies one element of a 2-dimension array.
Copy linkTweet thisAlerts:
@GudlifeAug 03.2012 — $_SESSION['somesession'][$somevariable]

->is an array.

$_SESSION['somesession'] is the array name

[$somevariable] is the position in the array

example:

<?php

session_start();

$A = array();

$name = "name";

$A[$name] = "something";

$_SESSION['test'] = $A;

print ($_
SESSION['test'][$name]);

//prints "something";

?>
×

Success!

Help @timothy12 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.27,
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,
)...