I have this snippet below, I'm trying to query if a cast is online or not (That part works when I take it outside the while loop) but then in the while loop run through until I find an online cast and then keep it there.
If I remove the break; in the ($stream == null) it will run the array but only for my first $url (So, the embed will run 4 times but only query the first $url).
So, if the stream is online. It will show all the streams in the array despite them being offline/online.
How can I make it so that it queries the array and executes the first embed of an online stream?
<?php
//On/Off
$url = "https://api.twitch.tv/kraken/streams/greatbritishbg";
$json = file_get_contents($url);
$json = json_decode($json);
$stream = $json->stream;
$streamers = array("greatbritishbg", "Gecko194", "jayw89","DethridgeCraft","reninsane");
while (list(, $val) = each($streamers)) {
$url = "https://api.twitch.tv/kraken/streams/".$val;
//var_dump($json);
$url1 = "https://api.twitch.tv/kraken/channels/". $val;
$json1 = file_get_contents($url1);
$json1 = json_decode($json1);
$logo = $json->preview->medium;
$game = $json1->channels->game;
if($stream != null){
echo'<header class="intro">';
echo'<div class="intro-body">';
echo'<div class="container">';
echo'<div class="row">';
echo'<div class="col-md-8 col-md-offset-2">';
echo'<div class="col-md-8 col-md-offset-2">';
echo'<h1 class="brand-heading">GBBG</h1>';
echo'<p class="intro-text"></p>';
echo "Live";
echo '<iframe src="http://www.twitch.tv/'. $val .'/embed" frameborder="0" scrolling="no" height="378" width="620"></iframe>';
}
if($stream == null){
echo'<header class="intro">';
echo'<div class="intro-body">';
echo'<div class="container">';
echo'<div class="row">';
echo'<div class="col-md-8 col-md-offset-2">';
echo'<h1 class="brand-heading">GBBG</h1>';
echo'<p class="intro-text">We are all offline at the moment.</p>';
echo'<p class="intro-text">When we are online, this page will change</p>';
break;
}
echo $val;
}
?>