具体执行代码如下:
实例
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta charset="UTF-8"> <title>PHP九九乘法表</title> </head> <body style="width: 90%; margin: 50px"> <table border="1" align="center" width="80%"> <?php $table = ''; for($r=1;$r<=9;$r++){ //一共9行,每行输出一个tr $table .= "<tr align='center'>"; //到第几行就有几列,所以要让列数小于等于行数,即$c<=$r for($c=1;$c<=$r;$c++){ //计算每一个表格中的乘积 $sum = $r*$c; //输出td $table .= "<td>{$c}*{$r}={$sum}</td>"; } $table .= "</tr>"; } echo $table; ?> </table> </body>
运行实例 »
点击 "运行实例" 按钮查看在线实例