0

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

2 Answers 2

3

You can use array dereferencing and add a required index directly to value, returned by Session::get('Tokens'):

echo Session::get('Tokens')['userToken'];
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that got it! Thanks so much. I'll accept this as soon as it lets me
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

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.