我正在为我的网站使用基本的 LAMP 服务器,并希望重写我拥有的与 Twitch 的 API 链接的脚本。我遇到的问题是试图找到与 foreach 相反的词,因为没有更好的词。
例如,我有一组名称,它们通过 URL 发送到 Twitch 服务器,如果其中一个名称当前正在流式传输,“流”将有很多值,如果它们当前没有流式传输,“流”将返回无效的。
这对于检查人员并显示他们在线非常有用,但我还需要它来显示离线的人,我不知道该怎么做。类似于 foreachelse 之类的东西。这是我下面的代码。谢谢。
<?php
$username = array("zeromi", "aerosgw", "krylen","tshirt_aion","snooky_aion","vashiro","papa456","vinley_aion","hanfkrokette","wtfast_siel","neckofthewood","paraproc","aionnae","uhiwi","mufflermankr","valorium","knighterrantry","soulune","relizex3","vinlockz","trevyn201","tiger529","xkegi","logsnsticks","meowform","uzuk3","kalzard01","squall_m","suyji","headpcgamer","sariett_siel");
$callAPI = implode(",",$username);
$data = json_decode(@file_get_contents('https://api.twitch.tv/kraken/streams?channel=' . $callAPI), true);
foreach ($data['streams'] as $streams){
$name = $streams['channel']['name'];
echo $name.'<br>';
}
?>