首页 >后端开发 >php教程 >php循环table实现一行两列显示的方法_PHP

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

WBOY
WBOY原创
2016-05-30 08:45:221054浏览

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

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

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

结果:

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn