kenprogrammer
2 weeks ago

Extract Exchange Rate from a JSON object

Posted 2 weeks ago by kenprogrammer

Below is a curl response from RapidAPI.com

Array ( [Realtime Currency Exchange Rate] => Array ( [1. From_Currency Code] => KES [2. From_Currency Name] => Kenyan Shilling [3. To_Currency Code] => USD [4. To_Currency Name] => United States Dollar [5. Exchange Rate] => 0.00948317 [6. Last Refreshed] => 2020-03-25 10:21:18 [7. Time Zone] => UTC [8. Bid Price] => 0.00947418 [9. Ask Price] => 0.00944733 ) )

Someone help me get extract the exchange rate. I have tried the code below to no avail.

$data = json_decode($response,true);
echo $data['Realtime Currency Exchange Rate']['Exchange Rate'];

Please sign in or create an account to participate in this conversation.