PHP beginner here. I want to display compared Data ($myCoins) from a JSON API, so that only those Items will be displayed that I first inserted into the $myCoins arrays, but I can't figure out how to get the code to operate the same with NAMES instead of NUMBERS.
Used API:
https://min-api.cryptocompare.com/data/pricemultifull?fsyms=BTC,ETH,XRB,MIOTA,XRP,XLM,TRX&tsyms=USD
CODE:
<?php
//// API
$coinData = json_decode(file_get_contents('https://min-api.cryptocompare.com/data/pricemultifull?fsyms=BTC,ETH,XRB,IOTA,XRP,XLM,TRX,LINK&tsyms=USD'), true);
// Arrays
$myCoins = array(
'BTC' => array ( 'balance' => 12.90 ),
'ETH' => array ( 'balance' => 122.23 ),
'XRB' => array ( 'balance' => 221.52 ),
'MIOTA' => array ('balance' => 233.00 ),
'XRP' => array ( 'balance' => 429.00 ),
'XLM' => array ( 'balance' => 1205.89 ),
'TRX' => array ( 'balance' => 5299.40 )
);
// Fetch the Coins
$numCoins = sizeof ($coinData['RAW']);
$portfolioValue = 0;
for ( $xx=0; $xx<$numCoins; $xx++) {
// Comparing to Data
$thisCoinSymbol = $coinData[$xx]['FROMSYMBOL'];
//
$coinHeld = array_key_exists($thisCoinSymbol, $myCoins);
// Only retour held
if ( !$coinHeld ) { continue; }
// names test:
echo $coinData[$xx]['FROMSYMBOL'];
};
?>
The Tutorial I used was made with an API that displays the Items as numbers, not the Item names like in the API I want to use.
Tutorial API:
https://api.coinmarketcap.com/v1/ticker/
So my console puts out a Undefined offset: 0
- Undefined offset: 7
on line $thisCoinSymbol = $coinData[$xx]['FROMSYMBOL']
; I understand that this is because $xx equals 0 - 7, because there are 8 Items under ['RAW'], and there is no 0-7 in the API I use.
How would i get the same result as the Tutorial but with the API I want to use?