-1

So i'm calling the Coinbase API.

<?php

$ctx = stream_context_create(["http"=>["user_agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0"]]);
$coinbase_coins = file_get_contents('https://api.coinbase.com/v2/prices/spot?currency=USD', true, $ctx);
$coinbase_coins = json_decode($coinbase_coins, true);

print_r($coinbase_coins);

?>

it returns the array

Array ( [data] => Array ( [base] => BTC [currency] => USD [amount] => 15715.2 ) )

however i just wants the 15715.2 so i can put it in a <span>.

What do I need to do?

Thank you.

Komplex9
  • 31
  • 5

1 Answers1

1

It is an array inside an array. Please try

$amount = $coinbase_coins['data']['amount'];

The $amount variable will now have 15715.2