I have this code to access the api and turn in into an array
`
$parameters = [
'convert' => 'USD',
'symbol' => 'BTC,XMR',
'aux' => 'is_fiat'
];
$headers = [
'Accepts: application/json',
'X-CMC_PRO_API_KEY: xxx'
];
$qs = http_build_query($parameters); // query string encode the parameters
$request = "{$url}?{$qs}"; // create the request URL
$curl = curl_init(); // Get cURL resource
// Set cURL options
curl_setopt_array($curl, array(
CURLOPT_URL => $request, // set the request URL
CURLOPT_HTTPHEADER => $headers, // set the headers
CURLOPT_RETURNTRANSFER => 1 // ask for raw response instead of bool
));
$response = curl_exec($curl); // Send the request, save the response
print_r(json_decode($response)); // print json decoded response
$array = get_object_vars(json_decode($response));
$decoded_json = json_decode($response, TRUE);
curl_close($curl); // Close request
echo '<pre>'; print_r($array); echo '</pre>';
This is the output
Array
(
[status] => stdClass Object
(
[timestamp] => 2024-02-29T09:51:16.590Z
[error_code] => 0
[error_message] =>
[elapsed] => 17
[credit_count] => 1
[notice] =>
)
[data] => stdClass Object
(
[BTC] => Array
(
[0] => stdClass Object
(
[id] => 1
[name] => Bitcoin
[symbol] => BTC
[slug] => bitcoin
[infinite_supply] =>
[is_fiat] => 0
[self_reported_circulating_supply] =>
[self_reported_market_cap] =>
[tvl_ratio] =>
[last_updated] => 2024-02-29T09:50:00.000Z
[quote] => stdClass Object
(
[USD] => stdClass Object
(
[price] => 62565.521930099
[volume_24h] => 91758833391.577
[volume_change_24h] => 101.4421
[percent_change_1h] => -0.15773114
[percent_change_24h] => 5.45946662
[percent_change_7d] => 20.44854353
[percent_change_30d] => 44.17944122
[percent_change_60d] => 46.45120123
[percent_change_90d] => 61.85312782
[market_cap] => 1228830646572.5
[market_cap_dominance] => 52.9737
[fully_diluted_market_cap] => 1313875960532.1
[tvl] =>
[last_updated] => 2024-02-29T09:50:00.000Z
)
)
)
)
[XMR] => Array
(
[0] => stdClass Object
(
[id] => 328
[name] => Monero
[symbol] => XMR
[slug] => monero
[infinite_supply] => 1
[is_fiat] => 0
[self_reported_circulating_supply] =>
[self_reported_market_cap] =>
[tvl_ratio] =>
[last_updated] => 2024-02-29T09:50:00.000Z
[quote] => stdClass Object
(
[USD] => stdClass Object
(
[price] => 140.09858558716
[volume_24h] => 72409439.318754
[volume_change_24h] => 25.6254
[percent_change_1h] => 2.04702992
[percent_change_24h] => 1.91404701
[percent_change_7d] => 13.25468147
[percent_change_30d] => -16.42126433
[percent_change_60d] => -15.56793655
[percent_change_90d] => -17.98997717
[market_cap] => 2578373000.537
[market_cap_dominance] => 0.1112
[fully_diluted_market_cap] => 2578373000.54
[tvl] =>
[last_updated] => 2024-02-29T09:50:00.000Z
)
)
)
)
)
)
I only need to access the [price] and convert it into two variables, one for each coin.
I havent had any luck doing so thus far.
I expect variables for bitcoin price and monero price.
Im not able to access the value itself by myself.