0

Here is the result on the page when using print_r($result);

Array
(
[result] => Array
    (
        [0] => Array
            (
                [username] => Elvis
            )

    )

)

I would like to pull this out of the array and use it as a PHP variable. I have tried extract, while loops and a variety of other solutions, but I am not finding the right syntax to make this happen. What is the easiest way? Thanks.

2 Answers 2

2

Try:

$var = $result['result'][0]['username'];
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I was sooo close.
You beat me by 35 seconds. :)
2

If the array is consistent, just like you showed it, then you just need

$username=$result['result'][0]['username'];

1 Comment

I appreciate it. @AbraCadaver was just before you on this, but you solution worked as well.

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.