PHP for带表的循环
正在尝试在表中输出以下内容:PHP for带表的循环,php,Php,正在尝试在表中输出以下内容: | 1 | 2 | 1 | 1 | 2 | 2 | 3 | 4 | (顶部1,2表示列标题。左侧1,2表示行标题) 代码 在那里的某个地方丢失了。可能在下面?另外,在代码的开头,缺少?>,我猜下面是$cols\u count=2在开始新的之前,请使用另一个变量保存跨行的计数 你的问题是什么?忽略刚刚添加到顶部的内容,然后忘记!但“是”应该有结尾;饭后 <?php $rows_count = 2; $cols_count = 2;
| 1 | 2 |
1 | 1 | 2 |
2 | 3 | 4 |
(顶部1,2表示列标题。左侧1,2表示行标题)
代码
在那里的某个地方丢失了
。可能在
下面?另外,在代码的开头,缺少?>
,我猜下面是$cols\u count=2
在开始新的之前,请使用另一个变量保存跨行的计数
你的问题是什么?忽略刚刚添加到顶部的内容,然后忘记!但“是”应该有结尾;饭后
<?php
$rows_count = 2;
$cols_count = 2;
$current_cell_value = 1;
?>
<?php if($rows_count > 0): ?>
<table>
<tr>
<th></th>
<?php for ( $cols = 1; $cols <= $cols_count; $cols++ ) : ?>
<th><?php echo $cols ?></th>
<?php endfor; ?>
</tr>
<?php for ( $rows = 1; $rows <= $rows_count; $rows++ ) : ?>
<tr>
<th>
<?php echo $rows ?>
</th>
<?php for ( $cells = 1; $cells <= $cols_count; $cells++ ) : ?>
<td><?php echo $current_cell_value++ ?></td>
<?php endfor; ?>
<?php endfor; ?>
</tr>
</table>
<?php endif; ?>