-1

I have a PHP variable that when I echo it will display an array that looks like this:

My Variable:

echo $mayVariable;

displays:

{"data":[{"id":"4756756575","name":"David","url":"https:\/\/www.somesite.com"}],"page":false}

I need to get the value from id within that array.

So I tried this:

echo $mayVariable[0]['id'];

But this doesn't give me anything.

I also tried:

echo $mayVariable['data']['id'];

and still I don't get anything in the echo...

Could someone please advise on this issue?

1

1 Answer 1

1

This JSON is an object array after decode it generally.

$json = '{"data":[{"id":"4756756575","name":"David","url":"https:\/\/www.somesite.com"}],"page":false}';

$arr = json_decode($json);

echo $arr->data[0]->id;//4756756575

If you use true as second parameter then:

$arr = json_decode($json, true);

echo $arr['data'][0]['id'];//4756756575
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.