php循环table实现一行两列显示的方法_php实例
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:12:44
Original
1468 people have browsed it
<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>
<?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>
Copy after login
如:是其他字符类型,需要用到函数转化:
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
Copy after login
结果:
Array
(
[0] => Hello
[1] => world.
[2] => It's
[3] => a
[4] => beautiful
[5] => day.
)
Copy after login
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
Latest Articles by Author
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11