PHP practice-print hollow diamond-jerrylsxu using for loop: 1. write the code to print the solid pyramid.
2. modify the code and empty the pyramid.
3. modify the code and reverse the pyramid
4. modify the reversed code and empty the pyramid.
5. modify the code and parameterize the specific number.
1. write the code to print the pyramid of solid gold:
";}?>
2,
2. improve code and empty the pyramid
";}?>
3. modify the code and reverse the pyramid
";}// Reverse for ($ I = 5; $ I >=0; $ I --) {// Print the space for ($ j = 0; $ j <= 5-$ I; $ j ++) {echo "" ;}// print * for ($ k = 1; $ k <= 2 * $ I-3; $ k ++) {echo "*";} echo"
";}?>
4. modify the reversed code, empty the pyramid, and remove the * sign in the middle to modify the code (if ($ I = 1 | $ I = 5) {// remove $ I = 5 and empty the center)
";}// Reverse the blank for ($ I = 5; $ I >=0; $ I --) {// Print the space for ($ j = 0; $ j <= 5-$ I; $ j ++) {echo "" ;}// print * for ($ k = 1; $ k <= 2 * $ I-3; $ k ++) {// question of how to empty the space and * ($ k = 2 * $ I-3 | $ k = 1) {echo "*";} else {echo "" ;}} echo"
";}?>
5. modify the code and parameterize the specific number: change the specific number 5 to $ n = 5, and then set the value of $ n to zoom in or out.
";}// Reverse the blank for ($ I = $ n; $ I >=0; $ I --) {// Print the space for ($ j = 0; $ j <= $ n-$ I; $ j ++) {echo "" ;}// print * for ($ k = 1; $ k <= 2 * $ I-3; $ k ++) {// question of how to empty the space and * ($ k = 2 * $ I-3 | $ k = 1) {echo "*";} else {echo "" ;}} echo"
";}?>
:
The final success is achieved. By the way, programming is not difficult, but it is difficult to find a solution to the problem. Therefore, everyone is good at thinking in the programming process. Although it took me half a day to think about it, I finally came up with it and solved the problem. so I usually need to practice it with my brains. Our programming capability can be improved. Only by practice can things be understood and knowledge points be mastered.