0

My friend let me look at his source code, and I just got around to it. I would ask him, but he's in vacation at switzerland.

$path = $_SESSION['a']['b'][$_GET['c']];

What exactly does that mean? Does it just concatenate those? If I sent in Cookie:a=/a/&b=b/ along with ?c=test.php , would the $path var be /a/b/test.php? If not, what would it be equal to?

5
  • 1
    If you're interested in what it would look like, why don't you run the code? Commented Mar 26, 2014 at 22:52
  • Look up arrays and subscripts. This is extracting a value from a nested array. Commented Mar 26, 2014 at 22:53
  • 1
    print_r($_SESSION); and echo $_GET['c']; and see if you can work it out. Commented Mar 26, 2014 at 22:54
  • 1
    $_SESSION is an array, the element with key a is accessed, then the element with the key b is accessed within a, finally the $_GET value of c is used to access an element of array b. ;) Commented Mar 26, 2014 at 22:54
  • They're just using the value of $_GET['c'] as a key for their array. Nothing really technical or fancy going on here at all. Commented Mar 26, 2014 at 22:59

2 Answers 2

1

$_SESSION['a']['b'][$_GET['c']] means a series of steps like the following steps:

$x_ = $_SESSION;
$x_2 = $x_['a'];
$x_3 = $x_2['b'];
$v = $_GET['c'];
$x_4 = $x_3[$v];

and you get and keep $x_4.

Long explanation: get a value under index 'a' from the session array, then get a sub value from that value (which is an array) under the index 'b', and so on.

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

1 Comment

oh, I can see what's happening. Thank you very much.
1
$_SESSION['a']['b'][$_GET['c']];

means that you are accessing a session variable named 'a'.

Where 'a' is assumed as a multidimensional array, assumed to have a key 'b' where it is also an array, an array assumed to have a key equal to whatever the value of $_GET['c'].

Let's assumed that $_GET['c'] is equal to 'c', so the assumed structure of your array would be:

$_SESSION['a'] = array(
    'b' => array(
         'c' => "This is the value you are trying to fetch."
    )
);

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.