问题
Currently, I'm dumping an array that is held within my laravel session, which successfully dumps the array:
<?php dd(Session::get('Tokens'));?>
This dumps an array with three elements, each with its own index
array(
"userToken":"value",
"secondToken":"value",
"thirdToken":"value",
);
I keep running into errors trying to get specifically the userToken. I've tried get('Tokens[userToken]')
but It's expecting a string only
How should I change this to be able to access any array key specifically
回答1:
You can use array dereferencing and add a required index directly to value, returned by Session::get('Tokens')
:
echo Session::get('Tokens')['userToken'];
回答2:
you can try this too
$value = session('Tokens');
and you can use $value like and array and you'll be able to call each value with the index like
$value['userToken']
hope it help
来源:https://stackoverflow.com/questions/54561150/laravel-getting-specific-array-index-from-session