Aiming at the problem that the beginner PHP cannot align the nine-nine multiplication table
Beginner PHP classic small problem - ninety-nine multiplication table (full alignment)
- code:
<?php for($a=1;$a<=9;$a++){ for($b=1;$b<=$a;$b++){ echo $a.'*'.$b.'='.$a*$b; if(($a*$b==6||$a*$b==8)&&$b==2){ echo' '; }else{ echo' '; } } echo'<br/>'; } ?>
- Renderings:
- Let PHP output the ninety-nine multiplication table. When there is a problem that cannot be completely aligned, it can be found that the back of 3*2=6; and 4*2=8; is not aligned. At this time, we write a judgment statement and output more spaces. We will find that the multiplication table is completely aligned.