0

I have this command line:

echo $_SESSION['info'];

It outputs this exact array with curly braces included:

{"_var1":"User","_var2":"Password"}

How to get the information from these variables? To output 'User' I've tried:

echo $_SESSION['info']['_var1'];

but doesn't output anything.

1 Answer 1

3

That's JSON. To get those values you need to use json_decode():

$info = json_decode($_SESSION['info'], true);
echo $info['_var1'];  // User

The above example gives you an array since your question was using them. But you can also get back an object:

$info = json_decode($_SESSION['info']);
echo $info->_var1;  // User
Sign up to request clarification or add additional context in comments.

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.