-1

I am extracting the name of each element from https://api.coinmarketcap.com/v2/ticker/

I'm doing this as so:

$foo = json_decode($foo, true);
$name = $foo['data'][`1`]['name'];

Which will give me Bitcoin. But how do I move onto the next element? Right now I am physically setting the ['1'] to be 1 which is Bitcoin. And as you can see from the data, its all random numbers to. Its not 1, 2, 3, 4. Its 1, 1027, 52 etc. So Essentially, do I do access the next element?

Paul
  • 127
  • 1
  • 1
  • 7
  • Never heard of foreach? If you use foreach, you can get the indexes and keep looping without knowing their name, getting just the content. – Alberto Oct 05 '18 at 13:01
  • 1
    http://php.net/manual/en/control-structures.foreach.php could be used. – user3783243 Oct 05 '18 at 13:01

1 Answers1

0

Use foreach($foo['data']) as $data) then you can get the name by $data['name'] inside the foreach.

M4ST3RX
  • 23
  • 7