摘要:
下文讲述使用php代码在页面上输出九九乘法表的示例分享,如下所示;
实现思路:
主要使用遍历的方式输出九九乘法表
例:
php 循环输出九九乘法表
echo "maomao365.com 示例分享\n";
echo "for 循环打印出九九乘法表";
for($j=1; $j<=9; $j++) {
for($i=1; $i<=$j; $i++) {
echo "{$i}x{$j}=".($i*$j)." ";
}
echo "\n";
}
echo "\n\n";
echo "while循环输出九九乘法表:"."\n";
$j = 1;
while($j<=9){
$i = 1;
while($i<=$j){
echo "{$i}x{$j}=".($i*$j)." ";
$i++;
}
echo "\n";
$j++;
}
echo "\n\n";
echo "do while循环输出九九乘法表:"."\n";
$j = 1;
do {
$i = 1;
do {
echo "{$i}x{$j}=".($i*$j)." ";
$i++;
} while($i<=$j);
echo "\n";
$j++;
} while($j<=9);
?>
php循环输出九九乘法表的示例分享