要求:
表格生成器;
2. 九九乘法表;
乘法表生成器
M_table.php
<?php
header("Content-type: text/html; charset=utf-8");
echo '<h2 align="center">乘法表生成器</h2><hr>';
//显示一个输入框以及按钮
echo <<<'TABLE'
<form align="center">
请输入乘法表大小:<input type="text" name="row" placeholder="例如:99乘法表输入9">
<button>提交</button>
</form>
TABLE;
$row=9;//声明一个变量ROW记录乘法表所需要的行,默认99乘法表
if (isset($_GET['row'])) {$row=$_GET['row'];} //判断用户是否有数据输入
//利用双循环输出乘法表
echo '<table align="center" cellpadding="3" cellspacing="5" border="10" style="background-color: yellowgreen;text-align:center;border-radius: 10px" >';
echo '<caption style="color: green;font-size: 2em">\''.$row.'\'\''.$row.'\'乘法表</caption>';//标题
//表格
for ($i=1;$i<=$row;$i++){
echo '<tr>';
for ($j=1;$j<=$i;$j++) {
echo '<td style="border: solid 1px whitesmoke;background-color: blanchedalmond;border-radius: 5px;min-width:70px">'.$j.'×'.$i.'='.$i*$j.'</td>';
}
echo '</tr>';
}
echo '</table>';效果图


Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号