The following summarizes two ways to implement Pyramid printing. one is to use a user-defined function, and the other is to use a for loop, in fact, both are used, but the former is more advanced. the code for customizing the function implementation pyramid is as follows :? Php * nbsp... the following summarizes two ways to implement Pyramid printing. one is to use a user-defined function, and the other is to use a for loop, in fact, both are used, but the former is more advanced.
User-defined function implementation pyramid. the code is as follows:
20) {return "must be between 1 and 20";} if ($ rows! = (Int) ($ rows) {return 'The number of rows must be an integer';} $ str = ""; if ($ sort) {for ($ I = 1; $ I <= $ rows; $ I ++) {$ str. ='
'; For ($ j = 1; $ j <= $ I; $ j ++) {if ($ j = 1) {for ($ k = 1; $ k <= ($ rows-$ I); $ k ++) {$ str. = ''; }}$ str. = '*'. '';}} else {for ($ I = $ rows; $ I >=1; $ I --) {$ str. ='
'; For ($ j = 1; $ j <= $ I; $ j ++) {if ($ j = 1) {for ($ k = 1; $ k <= ($ rows-$ I); $ k ++) {$ str. = ''; }}$ str. = '*'. '';}}return $ str;} echo fun_py (9, false );
Next we will implement a pyramid shape object, which also uses the for loop. the code is as follows:
= $ A; $ B --) {echo "" ;}for ($ c = 1; $ c <=$ B; $ c ++) {echo "*". "";} echo"
";}
The code is as follows:
= 1; $ a --) {for ($ B = 10; $ B >=$ a; $ B --) {echo "" ;}for ($ c = 1; $ c <= $ B; $ c ++) {echo "*". "";} // open-source phprm.com echo"
";}
Address:
Reprinted at will, but please attach the article address :-)