嵌套for循环
<?php $sum=0; for ($i=1; $i<=9; $i++) { for ($j=1; $j<=$i; $j++) { $sum=$i*$j; echo $j,"*",$i,"=",$sum; echo " "; } echo "<br>"; } ?>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表格</title> </head> <body> <table> <?php for ($i=1; $i <=9; $i++){?> <?php if ($i%2!=0){?> <tr style="background-color: #0fff00"> <?php }else{ ?> <tr><?php } ?> <?php for ($j=1; $j<=$i; $j++) {?> <td width="80px"> <?php $sum=$i*$j; echo $j,"*",$i,"=",$sum; ?> </td> <?php } ?> </tr> <?php } ?> </table> </body> </html>