Could you please give me a detailed explanation of how the multiplication table is calculated? I really can’t figure it out. It’s going to explode.╮(╯▽╰)╭
for ($i = 1 ; $i < 10 ; $i ){
for ( $j=1; $j<=$i; $j ){
echo $j.'x'.'$i'.'='.($i*$j).'';
}
echo '<br />';
}
清楚叛逆者2017-09-02 09:20:34
<?php //循环9次,表示9列,如同:1*1=1的1,2*1=2的2 for($i=1;$i<10;$i++){ //上面1次循环在这个循环9次,表示$i行如同:1*1=1的1,1*2=2的1和2 for($k=1;$k<$i;$k++){ //输出如同:2*2=4; 表示空格也可以用\t代替 echo $k."*".$i."=".$i*$k." "; } //每一次次循环换行 echo "<br />"; }
ringa_lee2017-09-02 09:05:58
The loop is easy to understand. You can bring the values in step by step to see what the result of the operation is. Look from the inside out, for example, starting from the first for loop outside:
for ($i = 1 ; $i < 10 ; $i++){ //第一次循环 $i=1; for ( $j=1; $j<=$i; $j++){ //第一次循环 $j=1; echo $j.'x'.'$i'.'='.($i*$j).''; //这个echo 结果为:1 x 1 = 1;依次类推 //里面的for第二次循环的时候就是$i=1;$j=2;这个echo 结果为:1 x 2 = 2; //里面的这个for循环结束,再从外面的for循环开始当$i=2,3,4,5.... } echo '<br />'; }