使用PHP foreach的多行?

我试图用foreach-call创建一个包含4行的表。 我的问题是,在结果中我在同一列中得到每个ID二十次。 我正在使用此代码:
<table  width="80%" border="0" cellpadding="10px">

   <?php foreach (array_chunk($items, 4) as $row) { ?>

      <?php     
         $i = 0;    
            foreach ($items as $item):      
            $class = null;      
            if ($i++ % 2 == 0) {            
            $class = ' class="altrow"';         
      } ?>

     <tr
        <?php echo $class;?>
     >  

  <?php foreach ($row as $item){ ?>         
     <td>
        <?php echo htmlentities ($item['Item']['id']); ?>
     </td>
  <?php } ?> 
<?php endforeach; ?>    
</tr> 
<?php } ?> 
</table>
知道如何才能获得每个ID一次吗?     
已邀请:
你每
$item
增加
$i
而不是每
$row
这是您正在寻找的修复方案吗? 编辑:Mikel有你的修复,添加这个来修复行错误(典型的我注意到第一个eck!)
<table  width="80%" border="0" cellpadding="10px">
<?php 
    $i = 0;
    $chunkedarray = array_chunk($items, 4);
    foreach ($chunkedarray as $row) {      
        $class = null;      
        if ($i++ % 2 == 0)           
            $class = ' class="altrow"';
        echo "<tr ".$class.">";
        foreach ($row as $item){ 
            echo "<td>";
            echo htmlentities ($item['Item']['id']); 
            echo "</td>";
        }
    echo "</tr>";
    }?>  
</table>
    

要回复问题请先登录注册