For those new to PHP, writing theNine-Nine Multiplication Tablein PHP is undoubtedly a very classicpracticequestion. It is quite a test of logic.
The so-called difficult thing is not difficult for those who know it, but it is not difficult for those who know it. For some veterans, this is really nothing. But for novices, it can train logical thinking.
If there are no restrictions, you may be able to type the entire code in two minutes. If you are proficient, you can also implement it in several ways. But what if you are asked to write the multiplication table for four angles? (It can continue to be extended)
The following will introduce several methods to implement the nine-nine multiplication table of PHP classic basic test questions:
1. Usefor loopto print nine Multiplication table:
"; }
2. Usewhile loopto print the multiplication table
"; $j++; }
3. Use do while loop to print the multiplication table
"; $j++; } while($j<=9);
Use a for loop to output the ninety-nine multiplication table in the form oftable
Angle one: (the most common conventional writing method)
"; for($j=1;$j<=9;$j++){ echo ""; for($i=1;$i<=$j;$i++){ echo " "; } echo "";{$i}*{$j}=".($i*$j)." "; } echo "
Angle two: (common to the conventional writing method X-axis symmetry)
"; for($j=9;$j>=1;$j--){ echo ""; for($i=1;$i<=$j;$i++){ echo " "; } echo "";{$i}*{$j}=".($i*$j)." "; } echo "
Angle three: (Y-axis symmetry with angle two)
"; for($j=9;$j>=1;$j--){ echo ""; for($z=0;$z<9-$j;$z++){ echo " "; } echo "";"; } for($i=1;$i<=$j;$i++){ echo " {$i}*{$j}=".($i*$j)." "; } echo "
Angle four: (Y-axis symmetry with conventional writing)
"; for($j=1;$j<=9;$j++){ echo ""; for($z=0;$z<9-$j;$z++){ echo " "; } echo "";"; } for($i=$j;$i>=1;$i--){ echo " {$i}*{$j}=".($i*$j)." "; } echo "
The above is the detailed content of Summary of methods to implement the ninety-nine multiplication table of PHP classic basic test questions. For more information, please follow other related articles on the PHP Chinese website!