1、表格生成器的实现
实现思路,用for嵌套循环实现,效果如下图:

i代码如下:
<?php
header('Content-Type: text/html; charset=utf-8');
echo <<< 'INPUT'
<form>
请输入表格的行数:<input type="text" name="row">列:<input type="text" name="col">
<button>提交</button>
</form>
INPUT;
$row = $_GET['row']; //获取行
$col = $_GET['col']; //获取列
echo '<table border="1" cellspacing="0" cellpadding="5" width="70%" >'; //输出表格
for($i=0;$i<$row;$i++){
echo '<tr>';
for ($j=0;$j<$col;$j++){
echo '<td></td>';
}
echo '</tr>';
}
echo '</table>';2、php打印九九乘法表
实现思路:for循环嵌套
实现效果:

代码如下:
<?php
header('Content-Type: text/html; charset=utf-8');
echo '<table cellspacing="0" cellpadding="5" width="500" align="center" style="margin-top: 30px">';
echo '<caption style="font-weight: bolder;color: #9A0000; font-size: 24px;">九九乘法表</caption>';
for ($i=1;$i<=9;$i++){
echo '<tr>';
for ($j=1;$j<=$i;$j++){
echo '<td style="border: 1px solid #5e5e5e">'.$j.'x'.$i.'='.($i*$j).'</td>';
}
echo '</tr>';
}
echo '</table>';
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号