$max_viewers ) { /* Should always be more than 0 at this point */ $max_viewers = $viewers; /* Set new nonzero value to be $max_viewers and loop 'foreach' until we have the highest viewer count */ $name = $mydata['channel']['display_name']; /* Store the display_name from API for user with highest viewer count */ } } } } else { /* None of the $channels I wanted are avaiable now, so fetch the most popular one */ $backupArray = json_decode(@file_get_contents('https://api.twitch.tv/kraken/streams?limit=1' . $callAPI), true); if ( $backupArray != null ) { foreach($backupArray['streams'] as $mydata){ if($mydata['_id'] != null) { $name = $mydata['channel']['display_name']; $viewers = $mydata['viewers']; } else { echo "Error in results from api.twitch.tv, cannot fetch a channel."; /* API responded but not with expected data */ } } } else { echo "Error in results from api.twitch.tv, probably cannot connect to server."; /* API probably did not respond at all */ } } ?>

Streamer:

" bgcolor="#000000">