0

I have this JSON

{
"AED_USD": {
"2019-08-01": 0.272242
}
}

When dumping this as an array I have:

array(1) { ["AED_USD"]=> array(1) { ["2019-08-01"]=> float(0.272242) } } 

I am trying to reach get the float value of 0.272242.

How do I get this value in PHP?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
R_life_R
  • 786
  • 6
  • 26

2 Answers2

2

You have to json_decode the string with true as second parameter to make it an array, and then just echo what you want using the name of the keys you have. Like so:

$string = '{
    "AED_USD": {
        "2019-08-01": 0.272242
    }
}';

$decode = json_decode($string, true);

echo $decode['AED_USD']['2019-08-01'];
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Lucas Arbex
  • 889
  • 1
  • 7
  • 15
1

To get the value in PHP, you can do

$value = $yourArray['AED_USD']['2019-08-01'];

If you want more information: https://www.php.net/manual/pt_BR/language.types.array.php

gustavo.lei
  • 141
  • 1
  • 7