How can I know the data of a PHP API?

0

A silly question as I can know the data of this Api using PHP this function foreach I'm forgetting how to use but what I want is to know the name and price_usd

$tick = file_get_contents('https://api.coinmarketcap.com/v1/ticker/');
$url = $tick;

//$json = file_get_contents($url);
$json = json_decode($tick, TRUE);


    foreach ( $json as $data ) {
        foreach ( $data as $value ) { 
            $name = $data[0]["name"];
            echo $name;
                echo '<br>';
            $price_usd = $data[0]["price_usd"];
            echo $price_usd;
        }
    }
    
asked by Shareiv 11.01.2018 в 17:40
source

1 answer

2

You do not need the second foreach, in $data the information of each of your elements comes already

foreach ( $json as $data ) {
    echo $data['name'];
    echo '<br>';
    echo $data['price_usd'];
    echo '<br>';
}
    
answered by 11.01.2018 / 17:49
source