99 multiplication Table Learning Goal: Understanding for loop, implementing printing, 99 multiplication table its principle. &NBSP;1 First Look at the code: < Php for ($i =1; $i <=9; $i + +) { for ($j =1; $j <=9; $j + +) { $i, ' * ', $j, ' = ', $i * $j, '; } echo ' <br/> ';} ?> print its values as follows:} //First, we analyze the, code splitting. A little bit of learning and understanding. Code Analysis: When the first layer for loop, run into print, 1-9 this is no problem. How much will it be when the second-tier for loop runs?//We'll split up next, looking at the following code and figure: for ($i =1; $i <=9; $i + +) { for ($j =1; $j <=9; $j + +) { echo $i, $j, ' <br/> '; } }//How do you understand this? First of all, our first level for, satisfies the condition. Its $i value is retained, and then self-increment ($i + +), the next layer for, and the second layer $j the same condition, also open execution, print out a value of 1, and then self-increment ($j + +) output 11. The first layer for value is again equal to 1,for again to satisfy the condition. This time since the last time since +1, then this time $j==2, if so, row 12. This double cycle can be looked at, the clock, and a lattice of walking. A minute to run a lap. Re-analysis and optimization: for ($i =1; $i <=9; $i + +) { for ($j =1; $j <=9; $j + +) { echo $i, ' * ', $ J, ' a '; Modify, between the two values, add a multiplication sign, and then give an empty compartment. } echo ' <br/> '; Add a newline here. } effect come out. The most perfect: &NBsp;for ($i =1; $i <=9; $i + +) { for ($j =1; $j <=9; $j + +) { echo $i, ' * ', $j, ' = ', $i *$ J, ' a '; Add an equal sign to its output and give the value of the operation before we learned $i * $j. } echo ' <br/> ';} This is achieved, the front effect. However, there is a final step, unlike the 99 multiplication table. The multiplication table, is the triangle bar. At this time, we change in the second layer for loop, in the second condition, we see $j <=9 this item, if we change to $j<= $i? At that time, when the $i value was 1, its $j was 1. When the $i value is 2, we will get 2 1 2 2 go to 2 3 o'clock, the condition is not set, end. Go $i=3, go again we will get 3 1 3 2 3 3 . In turn. The effect is not there. The codes and figures are as follows: for ($i =1; $i <=9; $i + +) { for ($j =1; $j <= $i; $j + +) { echo $j, ' * ', $i, ' = ', $i * $j, '; } echo ' <br/> '; } figure below: a small problem, How to print out the inverted triangle. Code reference: <? Phpfor ($i =9; $i >=1; $i-) { for ($j =1; $j <= $i; $j + +) { echo $j, ' * ', $i, ' = ', $i * $j, '; } echo ' <br/> '; } ?>& nbsp, when fully understood, the true meaning of the two, hand-out, then the for loop can still beat youIt?
Six. PHP Small Project (1) 99 multiplication table