-1

I'm trying to acces to range but is tnot working

  $json = '{"range":[[1,2,20],[3,4.5]]}';
  var_dump(json_decode($json->'range'));//doesn't work
  var_dump(json_decode($json['range']));//doesn't work

Whay is the way to acces to range?

afdi5
  • 307
  • 2
  • 13

2 Answers2

2

You need to json_decode() your JSON string first to turn it into an object. After that you can access the object properties with the -> operator.

So the correct way is this

var_dump(json_decode($json)->range));

But it is more readable if you split it into multiple statements:

$decoded = json_decode($json);

var_dump($decoded->range);
Daniel
  • 10,641
  • 12
  • 47
  • 85
1

you must use this one.

json_decode($json)->range;
Şafak Çıplak
  • 889
  • 6
  • 12