0

json data looks like this:

{"name":{"id":55555555,"name":"name" ...}}

echo $id[0]["id"]; returns

Undefined offset: 0 in C:\xampp\htdocs\index\lol\time.php on line 12

only echo $id["name"]["id"]; returns the desired id.

The problem is that the "name" key is not static and will change every request, so how can i access the id?

3
  • 1
    Use array_keys() Commented Jun 6, 2016 at 15:23
  • 1
    if theres only ever going to be a single key present you might be able to use array_values($id)[0]. Commented Jun 6, 2016 at 15:23
  • Thanks guys, it works :) Commented Jun 6, 2016 at 15:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.