在偶数上添加 tr 元素

  • 本文关键字:tr 元素 添加 php html
  • 更新时间 :
  • 英文 :


所以我有一个<tr>,我想每隔 2 次打开<tr>并关闭一次</tr>

所以我试过这个:

<?php $i = 0; foreach($blogs as $story): ?>
<?=(($i % 2) == 0) ? "<tr>" : null ?>
 <td>my stuff</td>
<?=(($i % 2) == 0) ? "</tr>" : null ?>
<?php ++$i; endforeach; ?>

但它每次都会增加,我需要有一个<tr>里面有两个<td>

<tr><td></td><td></td></tr>
不应该

<?=(($i % 2) == 1) ? "</tr>" : null ?>因为你有它<?=(($i % 2) == 0) ? "</tr>" : null ?>

最新更新