试图输出表中的以下内容:PHP for循环与表
| 1 | 2 |
1 | 1 | 2 |
2 | 3 | 4 |
(顶部1,2代表列标题左1,2-表示行标题)
代码
<?php
$rows_count = 2;
$cols_count = 2;
?>
<?php if($rows_count > 0): ?>
<table>
<tr>
<th></th>
<?php for ($cols = 1; $cols <= $cols_count; $cols++) : ?>
<th><?php echo get_post_meta($post_id, $prefix . 'col_title_' . $cols, true); ?></th>
<?php endfor; ?>
</tr>
<?php for ($rows = 1; $rows <= $rows_count; $rows++) : ?>
<tr>
<th><?php echo get_post_meta($post_id, $prefix . 'row_title_' . $rows, true); ?></th>
<?php for ($cells = 1; $cells <= $cols_count; $cells++) : ?>
<td><?php echo get_post_meta($post_id, $prefix . 'cell_value_' . $cells, true); ?> <?php echo $cells; ?></td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</table>
<?php endif; ?>
问题,如何得到它牛逼o输出上面的表格?所以基本上需要$ cell在下一行循环中继续。
即行1值1,值2 行2值3,值4
在此先感谢您的帮助。
什么是你的问题? – Barmar
见上面,对不起 – Max