php循环table实现一行两列显示的方法

<table cellspacing="1" cellpadding="0"> <tr> <td bgcolor="#FFFFFF">第一列</td> <td bgcolor="#FFFFFF">第二列</td> </tr> <tr> <?php $setarr = array(0,1,2,3,4,5,6,7,8,9); //相当于数据库获取的数组 $i=0; foreach($setarr as $val){ $i++; ?> <?=$val?> <?php if($i%2==0&&$i<count($setarr)) echo '</tr><tr>'; } ?> </tr> </table>

如:是其他字符类型,需要用到函数转化:

<?php $str = "Hello world. It's a beautiful day."; print_r (explode(" ",$str)); ?>

结果:

Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/27a495962b3bfb5d7380c286bea41d91.html