0

I've got this JSON Output:

{"ok":true,"license":"CC BY 4.0 -  http:\/\/creativecommons.tankerkoenig.de","data":"MTS-K","prices":{"90d20149-1047-43d3-9b80-4c6f7fd22499":{"status":"open","e5":1.479,"e10":1.459,"diesel":1.259}}}

and I want to get the values of e5, e10 and diesel into a PHP Variable. Like:

$Tankstelle = json_decode($json);
$PriceE5 = (float)utf8_decode($Tankstelle->prices->90d20149-1047-43d3-9b80-4c6f7fd22499->e5);

But it doesnt work, as there is this integer as a value. Can you help me? Thank you!

zixina
  • 1

1 Answers1

0

If value '90d20149-1047-43d3-9b80-4c6f7fd22499' is variable you can do it in the following way:

$json = '{"ok":true,"license":"CC BY 4.0 -  http:\/\/creativecommons.tankerkoenig.de","data":"MTS-K","prices":{"90d20149-1047-43d3-9b80-4c6f7fd22499":{"status":"open","e5":1.479,"e10":1.459,"diesel":1.259}}}';
$Tankstelle = json_decode($json, true);
$item = array_pop($Tankstelle['prices']);
$PriceE5 = (float)utf8_decode($item['e5']);
Andrej
  • 7,474
  • 1
  • 19
  • 21