<?phpecho "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/>"; }
时间: 2024-10-13 21:48:02