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条)

报告相同问题?

悬赏问题

  • ¥30 matlab ode45 未发现警告,但是运行出错
  • ¥15 vscode platformio
  • ¥15 代写uni代码,app唤醒
  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开