cpcdev
cpcdev

Reputation: 1222

Display symbol name from REST API endpoint

I'm trying to extract the "symbol names" from this REST API endpoint:

https://rates.50x.com/market/

$fiftyx_coins = file_get_contents('https://rates.50x.com/market/');
$fiftyx_coins = json_decode($fiftyx_coins, true);

foreach ($fiftyx_coins as $coin => $coindata) {
    echo $coindata . "<br>";
}

It is just echoing "Array" though.. How can I access the symbol names?

By symbol names, I mean "TAU", "BNB", "OMG", returned by the endpoint.

Thanks!

Upvotes: 0

Views: 500

Answers (2)

Lawrence Cherone
Lawrence Cherone

Reputation: 46620

If you only want an array of the symbols you can use array_keys(), then you can implode them to output.

$fiftyx_symbols = array_keys($fiftyx_coins);
echo implode('<br>', $fiftyx_symbols);

Upvotes: 2

Marco
Marco

Reputation: 57593

I'm pretty sure you have to correct last part of the code:

$fiftyx_coins = file_get_contents('https://rates.50x.com/market/');
$fiftyx_coins = json_decode($fiftyx_coins, true);

foreach ($fiftyx_coins as $coin => $coindata) {
    echo $coin . "<br>";
}

When you decode JSON and use foreach part you have symbol names in $coin and symbol values (an array of name-values) on $coinvalues

Upvotes: 2

Related Questions