Heim >Backend-Entwicklung >PHP-Tutorial >怎么循环输出含有tr的td
如何循环输出含有tr的td
eg:$arr1=array("a","b","c","d","e","f","g");
循环上面的。
得到如下效果
foreach(array_chunk($arr1,4) as $v){ echo "<tr>\n"; foreach($v as $t) echo "<td>".$t."</td>\n"; echo "</tr>\n";};<br><font color="#e78608">------解决方案--------------------</font><br>$arr1=array("a","b","c","d","e","f","g"); <br><br>$i = 1;<br>echo '<tr>';<br>foreach ($arr1 as $key=>$val)<br>{<br> echo '<td>' , $val, '</td>';<br> if($i%4 == 0) echo "</tr><tr>";<br> ++$i;<br>}<br>echo '</tr>';<br><br><div class="clear"> </div>