PHP While Loop问题服务器挂起一段时间后出错


PHP While Loop problems server hang for a while then error

尝试通过twitters公共api回显所有用户名。如果我跳过while循环,我就能让它工作。但我似乎无法让它与我的循环一起工作。

 $url = 'https://api.twitter.com/1.1/followers/list.json';
$getfield = '?screen_name=zarazentio1&count=200';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$result = $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();

   $results = json_decode($result,true);
   $getfield = $getfield.'&cursor='.$results["next_cursor"];
   echo $nextpage;
 ##  echo $results["users"]["2"]["screen_name"];
   foreach($results["users"] as $follow) {
   echo "</br>";
   echo $follow["screen_name"];

            }while ($results = $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest());

当我这样做的时候,它似乎只是挂了一段时间,然后我从我的主机那里得到了错误。如果我去掉这个部分(最后一部分)。

while ($results = $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest());

剧本很管用。我从第一页就能查到名字。我已经检查过了,所以我得到了下一页的光标。但我想我根本不理解WHILE循环函数。

您似乎正在尝试将foreach和while结合起来,这在PHP中是不可能的。如果您想在满足某些条件后停止迭代,只需使用:if($condition) { break;}