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

怎么循环输出含有tr的td

WBOY
Release: 2016-06-13 13:30:06
Original
870 people have browsed it

如何循环输出含有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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template