dsc56927 2014-01-09 02:33
浏览 161
已采纳

while循环与赋值运算符

I can't seem to figure out how this loop works in PHP:

$people = array();
while($row = $result->fetch_assoc())
    $people[] = $row;

It seems as though the loop would just keep going, infinitely. But, it doesn't How exactly does this work? Can someone explain it to me step-by-step? I'm guessing that the while loop could also be written like this:

while(($row = $result->fetch_assoc()) == true)
  • 写回答

3条回答 默认 最新

  • doujiunai2169 2014-01-09 02:35
    关注

    The fetch_assoc fetches one result row at a time and stores it in $row. Since this is in a loop, you are fetching until you run out of rows

    In the loop you are essentially pushing the $row value into a $people array

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?