codacopia
codacopia

Reputation: 2501

Trying to Pull Single PHP Variable from JSON Array

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.

Upvotes: 0

Views: 63

Answers (2)

TecBrat
TecBrat

Reputation: 3729

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

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

Upvotes: 2

AbraCadaver
AbraCadaver

Reputation: 78974

Try:

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

Upvotes: 2

Related Questions