首頁 >後端開發 >php教程 >怎么循环输出含有tr的td

怎么循环输出含有tr的td

WBOY
WBOY原創
2016-06-13 10:24:511104瀏覽

如何循环输出含有tr的td
eg:$arr1=array("a","b","c","d","e","f","g"); 
循环上面的。

得到如下效果


a
b
c
d


e
f
g



以此类推,请问如何用PHP写出来

------解决方案--------------------
PHP code
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>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn