9*9乘法表
Posted Wzybnzy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了9*9乘法表相关的知识,希望对你有一定的参考价值。
<?php
echo "99乘法表<br/>";
echo "for循环<br/>";
for ($i = 1; $i <= 9; $i++) {
for ($j = 1; $j <= $i; $j++) {
echo " " . $j . "*" . $i . ‘=‘ . $i * $j . " ";
}
echo "<br/>";
}
echo "<br/><br/>";
echo "while循环<br/>";
$m = 1;
while ($m < 9) {
$m++;
$n =1;
while ($n <= $m) {
echo " " . $n . "*" . $m . ‘=‘ . $n * $m . " ";
$n++;
}
echo "<br/>";
}
echo "<br/><br/>";
echo "dowhile<br/>";
$x = 1;
do {
$y =1;
do {
echo " " . $x . "*" . $y . ‘=‘ . $x * $y . " ";
$y++;
} while ($y <= $x);
$x++;
echo "<br/>";
} while ($x <= 9);
echo "<br/><br/>";
echo "foreach<br/>";
$arr = array(1,2,3,4,5,6,7,8,9);
foreach ($arr as $key=>$val1) {
foreach ($arr as $key => $val2) {
if ($val2 <= $val1) {
echo $val1 . "*". $val2 ."=". $val1 * $val2 . " ";
}
}
echo "<br/>";
}
以上是关于9*9乘法表的主要内容,如果未能解决你的问题,请参考以下文章
跳出多层循环体(做标记)-求最小公倍数-9*9星星矩阵-9*9正斜三角-9*9反斜三角-侧边9*9正斜三角-九九乘法表-求任意个数字之和