非常需要帮助,如何在3中打破模数可见,但是我需要它循环或在单独的html表中继续循环,因为在我的我..它将像下面那样继续循环
Sample_table
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
当前输出
| 1 | 2 | 3 |
| 4 | 5 | 6 |
期望的输出
HTML table page 1
| 1 | 2 | 3 |
HTML table page 2
| 4 | 5 | 6 |
我当前的代码
//$resultz = explode('xxx',$result['0']['tanning']);
//$i = 0;
$i=0;
foreach($result as $results) {
if ($i%3 == 0) {
echo "</tr><td><b>TITLE <br></b></td>";
echo "<td>".$results['data1']."</td>";
} else {
echo "<td>".$results['data1']."</td>";
}
$i++;
}
echo "</tr>";
谢谢
可以有很多解决方案。可能是这样:
<?
// controller
$array = array(
1,
2,
3,
4,
5,
6,
7
// ...
);
$column = 0;
$row = 0;
$maxI = 3; // max number of columns
$arrayNew = array();
foreach($array as $key => $val){
$column++;
$arrayNew[$row][$key] = $val;
if ($column == $maxI){
$column = 0;
$row++;
}
}
if( $column >= 1) { // add empty values so that the table is beautiful (if necessary)
for($i = 0; $i < ($maxI - $column); $i++){
$arrayNew[$row][] = '';
}
}
// template
foreach ($arrayNew as $keyValueArray => $valueArray) { ?>
<table>
<tr>
<?foreach ($valueArray as $key => $value) { ?>
<td><?=$value?></td>
<?}?>
</tr>
</table>
<?}