看看这张表:
<?php
echo '<table>';
for($i = 1;$i<99;$i++)
{
$i = intval($i);
if ($i / 3 == intval($i / 3))
{
echo "<tr><td>this is third tr</td></tr>";
}
else
{
echo "<tr><td>this is first or second</td></tr>";
}
}
输出类似于
this is first or second
this is first or second
this is third tr
this is first or second
this is first or second
this is third tr
this is first or second
this is first or second
this is third tr
是否有更优雅的方式来检测ALWAYS第三个tr?
答案 0 :(得分:4)
<?php
echo '<table>';
for($i = 1;$i<99;$i++){
if ($i % 3 == 0){
echo "<tr><td>this is third tr</td></tr>";
}else{
echo "<tr><td>this is first or second</td></tr>";
};
};
echo "</table>";
?>
答案 1 :(得分:1)