-2

I am new to PHP and I am trying to build a joomla module that displays the current BTC Price. I am using this API: https://api.coindesk.com/v1/bpi/currentprice.json

I cannot find out how to access the USD and EUR "rate". This is where I am currently (ignore the var_dump, I used it to verify I was receiving data):

<?php

$curl_handle = curl_init();

$url = "https://api.coindesk.com/v1/bpi/currentprice.json";

curl_setopt($curl_handle, CURLOPT_URL, $url);


curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);

$curl_data = curl_exec($curl_handle);

curl_close($curl_handle);


$response_data = json_decode($curl_data);
//var_dump($response_data);
$user_data = $response_data;

foreach ($user_data as $user) 
{
   foreach ($user as $key => $value)
   {
       echo $key;
       echo "<br />";
   }
}
Antonis
  • 1
  • 1
  • 1
    Does this answer your question? [How to extract and access data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-to-extract-and-access-data-from-json-with-php) – Syscall Jan 10 '22 at 11:56
  • If you are doing Joomla development, @Antonis, I'll urge you to join [joomla.se] Stack Exchange. – mickmackusa Jan 31 '22 at 00:21

1 Answers1

0
echo $response_data['bpi']['USD']['rate'];

This seems to work just fine. Will mark it as solved, leaving it as it might help someone...

Antonis
  • 1
  • 1