我有一个包含660条记录的多峰阵列。当我运行我的foreach时,我应该为每个传球获得一个记录,但我得到的只是第一个记录。我提高了我的错误报告,我什么也没收到,我没有在foreach中分配任何内存(只是输出表格内容)。
代码如下所示:
$totCount = count($funnel);
echo "We found $totCount log entries<br><br>\n"; // 66x records!
echo "<table border='1'>\n";
echo "<tr><th>Visitor</th><th>Date</th><th>Time/Page ---></th></tr>\n";
$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>\n"; // 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>\n"; // start a new row
echo "<td>$ip</td><td>$date</td>\n";
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";
上面一行说我有一个66x的访问者,nRec是1,显示foreach执行了一次。
任何帮助将不胜感激!
答案 0 :(得分:4)
foreach之后的半冒号?
foreach($funnel as $page);
应该是:
foreach($funnel as $page)
答案 1 :(得分:1)
删除';'在你的foreach陈述之后 - 它基本上消除了它。