1
 $tick = file_get_contents('https://api.coinmarketcap.com/v2/ticker');
 $data = json_decode($tick, TRUE);
 var_dump($data);

result of $data when filter by this code :

if($key == 1027)
$me=$value;

array (size=10)


'id' => int 1
  'name' => string 'Bitcoin' (length=7)
  'symbol' => string 'BTC' (length=3)
  'website_slug' => string 'bitcoin' (length=7)
  'rank' => int 1
  'circulating_supply' => float 17271050
  'total_supply' => float 17271050
  'max_supply' => float 21000000
  'quotes' => 
    array (size=1)
      'USD' => 
        array (size=6)
          'price' => float 6501.77307056
          'volume_24h' => float 3202089755.7065
          'market_cap' => float 112292447790
          'percent_change_1h' => float 0.14
          'percent_change_24h' => float -0.67
          'percent_change_7d' => float 1.37
  'last_updated' => int 1537115604

data i need of this result are for insert in database

name' => string 'Ethereum' (length=8)
'symbol' => string 'ETH' (length=3)
'circulating_supply' => float 101996833
  'total_supply' => float 101996833
  'max_supply' => null
  'quotes' => 
    array (size=1)
      'USD' => 
        array (size=6)
          'price' => float 218.486594482
          'volume_24h' => float 1511169511.1798
          'market_cap' => float 22284940724
          'percent_change_1h' => float 0.7
          'percent_change_24h' => float -2.81
          'percent_change_7d' => float 8.08
  'last_updated' => int 1537116039

now please run this code

$tick = file_get_contents('https://api.coinmarketcap.com/v2/ticker');
 $data = json_decode($tick, TRUE);
 var_dump($data);

there are more than 100 digital coins in this array i need 3 coins of thia array not any more BTC,ETH,Litecoin whats the best way for filter this !!!

puriya
  • 25
  • 8

1 Answers1

0

Now the question is much clearer.

You can use array_filter to obtain that.

Consider the following code:

$tick = file_get_contents('https://api.coinmarketcap.com/v2/ticker');
$data = json_decode($tick, TRUE);

$symbols = array("BTC", "ETH", "LTC");
$filtered = array_filter($data['data'], function($elm) use ($symbols){
    return (in_array($elm['symbol'], $symbols));
});
echo print_r($filtered, true);

I filtered by symbol but you can change the filter field by changing the (in_array($elm['symbol'], $symbols)) to other field then symbol

dWinder
  • 11,597
  • 3
  • 24
  • 39