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 />';
}
即使是小小的人物,也有他自己精彩的故事
<?php //循環(huán)9次,表示9列,如同:1*1=1的1,2*1=2的2 for($i=1;$i<10;$i++){ ????//上面1次循環(huán)在這個(gè)循環(huán)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." "; ????} ????//每一次次循環(huán)換行 ????echo?"<br?/>"; }
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++){ ????//第一次循環(huán) ????$i=1; ????for?(?$j=1;?$j<=$i;?$j++){ ????//第一次循環(huán) ????$j=1; ????????echo?$j.'x'.'$i'.'='.($i*$j).''; ????????//這個(gè)echo?結(jié)果為:1?x?1?=?1;依次類推 ????????//里面的for第二次循環(huán)的時(shí)候就是$i=1;$j=2;這個(gè)echo?結(jié)果為:1?x?2?=?2; ????????//里面的這個(gè)for循環(huán)結(jié)束,再?gòu)耐饷娴膄or循環(huán)開始當(dāng)$i=2,3,4,5.... } ????echo?'<br?/>'; }