21,886
社区成员
发帖
与我相关
我的任务
分享
<style>
div{
margin:0;
padding:0;
}
.box{
width:300px;
}
.box div{
width:100px;
float:left;
}
</style>
<?php
$arr = array(2,3,5,6,5,5,5,6,6,55,6,6,5,5,55,32025);
echo '<div class="box"><div>'.implode('</div><div>',$arr).'</div></div>';
$arr = array(2,3,5,6,5,5,5,6,6,55,6,6,5,5,55,32025);
echo "<table border=1>";
for ($i=0; $i<ceil(count($arr)/3); $i++){
$result = array_slice($arr, $i*3, 3);
echo "<tr>";
foreach($result as $r){
echo "<td>$r</td>";
}
echo "</tr>";
}
echo "</table>";
$col = 3;
$i=0;
foreach($arr as $a)
{
if ($i%$col==0) echo " <tr>";
echo " <td>" . $a " </td>";
if ($i%$col==$col - 1) echo " </tr>";
$i++;
}
$col = 3;
$i=0;
$isEnd=0;
foreach($arr as $a)
{
if ($i%$col==0) {
echo " <tr>";
$isEnd = 1;
}
echo " <td>" . $a " </td>";
if ($i%$col==0 && $isEnd == 1){
$isEnd = 0;
echo " </tr>";
}
$i++;
}
$arr = array(1,2,3,4,5,6,7,8,9,10);
$col = 3;
$i=0;
echo("<table border=1><tr>");
foreach($arr as $a)
{
if ($i%3==0&&$i>0) echo "</tr><tr>";
echo " <td>$a</td>";
$i++;
}
if ($i%3>0) echo str_repeat("<td> </td>",3-$i%3);
echo("</tr></table>");
echo str_repeat("<td> </td>",3-$i%3);