<table width="100%" border="0" cellspacing="1" cellpadding="0" > <tr> <td align="center" bgcolor="#FFFFFF">第一列</td> <td align="center" 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. )