dongyou7739 2011-08-26 21:45
浏览 124
已采纳

php foreach在第一次迭代后停止

OK, I'm baffled.

I have a multidemionsal array with 660 records in it. When I run my foreach I should get one record for each pass but what I get is just the first record. I upped my error reporting and I get nothing back and I'm not allocating any memory in the foreach (just outputting table contents).

Code looks like this:

$totCount = count($funnel);

echo "We found $totCount log entries<br><br>
";  //  66x records!
echo "<table border='1'>
";
echo "<tr><th>Visitor</th><th>Date</th><th>Time/Page ---></th></tr>
";
$nCount = 0;  // number of records
$nRec = 0;
$ip   = "";   // current records ip address
$date = "";   // current records date
$time = "";   // current records time
$file = "";   // file that was viewed

foreach($funnel as $page);
{
  // process each record
  $nRec++;

  // if the ip's are different, this is a new visitor
  if( strcmp($page['ip'], $ip) != 0 )
  {
    if($nCount > 0) // only end a row if its not the first one
      echo "</tr>
"; // close out this row

    // update the variables
    $ip = $page['ip'];      // save the new visitors ip
    $date = $page['date'];  // save the new visitors date
    $time = $page['time'];  // save the new visitors time
    $file = $page['path'];  // save the new visitors file viewed

    echo "<tr>
"; // start a new row
    echo "<td>$ip</td><td>$date</td>
";
    echo "<td>$time<br>$file</td>";  

    $nCount++;        
  }
  else
  {
    // not a new visit
    $time = $page['time'];  // what time was this page viewed?
    $file = $page['path'];  // where did they go next?
    echo "<td>$time<br>$file</td>";  
  }
}
echo "</table>";
echo "<br>Processing Complete. $nCount visitors of $totCount/$nRec";

The above line says I had 1 visitor of 66x and nRec is 1 showing the foreach executed 1 time.

Any help would be appreciated!

  • 写回答

2条回答 默认 最新

  • dongqie4402 2011-08-26 22:23
    关注

    Semi colon after the foreach?

    foreach($funnel as $page);
    

    Should be:

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

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入