for循环输出:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<table border="1">
<?php
for ($i = 1; $i <= 9; $i++) {
echo "<tr>";
for ($j = 1; $j <= $i; $j++) {
echo "<td>";
echo "$i*$j=" . $i * $j;//"$i*$j="为输出算式后面不带引号的是输出结果
echo "</td>";
}
echo "</tr>";
}
?>
</table>
</body>
</html>
while循环输出:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1">
<?php
$i = 1;
while ($i <= 9) {
$j = 1;
echo '<tr>';
while ($j <= $i) {
echo '<td>';
echo "$i*$j=" . $i * $j;
echo '</td>';
$j++;
}
echo '</tr>';
$i++;
}
?>
</table>
</body>
</html>
dowhile循环输出
<table border="1">
<?php
$i = 1;
do {
echo "<tr>";
$j = 1;
do {
echo "<td>";
echo "$i * $j=" . $i * $j;
echo "</td>";
$j++;
} while ($j <= $i);
echo "</tr>";
$i++;
} while ($i <= 9);
?>
</table>
[scode type="red"]代码需要运行在PHP环境中。安装环境可以看https://xxhzm.cn/archives/251/[/scode]
Comments | NOTHING