It is necessary to remember than in PHP arrays are actually hashmaps. That is to say that they are an associative array of key => value pairs.
$_SESSION['access_token'] = $access_token;
echo $access_token[2];
This means the above code will look in the $access_token array not at position 2 but at key 2. We can see from your vardump there is no key 2:
array(4) {
["oauth_token"]=> string(50) "81920494-vHspkpas4WiOYoFKCgto85mW2XeTxuA130MwcHHWb
["oauth_token_secret"]=> string(42) "WwIYybFivEwZQ1ORbeqY1irHT385EIuh27alWy9ED4"
["user_id"]=> string(8) "81920494"
["screen_name"]=> string(12) "KlareBrennan"
}
Note that for most indexed arrays this functions exactly the same way, which is what leads to your confusion. Please consider the following code:
<?php
$blah = array();
$blah['mykey'] = "My first key.";
$blah[] = "My second key.";
$blah[1] = "My third key.";
$blah[] = "My last key.";
var_dump($blah);
And it's results:
array(4) {
["mykey"]=>
string(13) "My first key."
[0]=>
string(14) "My second key."
[1]=>
string(13) "My third key."
[2]=>
string(12) "My last key."
}
We can see that if no key is specified the next available key is use; and in this numerals are assigned as keys for the key-value pair, but that they can live alongside string keys. For this reason array_values() is a useful function if you want to iterate over all the contents of an array.
var_dump($access_token);["user_id"], then the key is["user_id"]. Only if the key says[2], then the key is[2].