-2

I have to make a loop from number 1 to the last line + echo,

How can this be done?

$api = file_get_contents($url);
$api = json_decode($api, true);

foreach.. // i need to loop from 1 - until the last
echo $api['available_channels']['1']["live"] .";
}
Biffen
  • 6,249
  • 6
  • 28
  • 36
sobigel
  • 11
  • 3
  • 2
    You should add your Json to question – Mesar ali Apr 22 '18 at 10:28
  • show some more details for $api last, means print value of $api – Pradeep Apr 22 '18 at 10:29
  • If you want to isolate columnar data from your array, there is a dedicated function for that. Please post sample input to give your question context. If you are doing something specific with the values (other than just echoing), you should describe your actual task. – mickmackusa Apr 23 '18 at 00:24
  • Possible duplicate of [php: loop through json array](https://stackoverflow.com/questions/4731242/php-loop-through-json-array) – mickmackusa Apr 24 '18 at 00:05

1 Answers1

0

Taking a punt, something like the following (untested as no sample data):

$api = file_get_contents($url);
$api = json_decode($api, true);

foreach($api['available_channels'] as $channel) {
    echo $channel["live"];
}
Progrock
  • 7,373
  • 1
  • 19
  • 25