What I’m seeing here:
You create an empty array $live, and an array $channels with the names you want to check.
Cool so far.
You then get all the objects from the online streams.
For every String in $channels, you set $live[$name] to null
So:
$live[“themittanidotcom”] = null;
$live[“djyumene”] = null; etc etc.
Then for every online Stream, you get all the “streams” array in the json.
You loop trough all the “streams” array elements in the json and call it $chdata
THEN you call $stream. what is $stream?
what is [“login”]? I don’t see that one anywhere in the json from the API
I suppose you mean, you get the name from that $chdata element: $chdata[“channel”][“name”]
so in $live, as key you use the streamer name, as value you put in the channel JSON
AFAIK apart from these mistakes I described above, the for each loop should work correctly.
one more note: $game and $url don’t work like you think, since you do not close/open the for each loop anywhere, the $game and $url will fail and be null, as the for loop will only work for the next 1 statement. (use brackets to include them)
even if you included them in the for each, they would return the game/url from the last streamer
So I’m not sure what the purpose of these is, but my best bet is, you would want to simply get these directly from the channel JSON object of that streamer. the way you try to extract it to a variable, either requires you to extract it in the very last for loop you posted. - or create an array with games/urls (which would be redundant)
EDIT:
<?php
// Channels to pull the stuff from
$live = array();
$channels = array("themittanidotcom", "djyumene", "daopa", "nightblue3", "cabochardlol", "moanygamer");
// This part does stuff ... and things! No touchie!
$streamData = json_decode(@file_get_contents("https://api.twitch.tv/kraken/streams?channel=".implode(",",$channels)), true);
foreach ($channels as $name) { ////// tmake sure the keys exist for later
$live[$name] = null;
}
foreach ($streamData["streams"] as $chdata) {
$live[$chdata["channel"]["name"]] = $stream["channel"];// For every live stream, use the name as key, channel JSON object as value
}
foreach ($live as $name => $channel) {
if($channel != null){
$game = $channel['game']; // you can load these here
$url = $channel['url'];
echo "<a href='http://twitch.tv/$name/embed' target='tbox'><b>$name $game Online</b></a><br>";
} else{
echo "<a href='http://twitch.tv/$name/embed' target='tbox'><b>$name Offline</b></a><br>";
}
}
?>
note: not the most beautifull or correct, but (I think) it works, simply reformatted yours