Home  >  Article  >  Backend Development  >  怎么循环输出含有tr的td

怎么循环输出含有tr的td

WBOY
WBOYOriginal
2016-06-13 13:30:06822browse

如何循环输出含有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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn