Home  >  Article  >  Backend Development  >  PHP loop through inverted pyramid

PHP loop through inverted pyramid

WBOY
WBOYOriginal
2016-07-29 09:16:221937browse

I found the Inverted Pyramid that I wrote when I was learning PHP a few months ago. It took me more than an hour to understand it. I was still depressed about how I wrote it back then. It turned out to be regular. Now I have refined the code and written it down. Code is something I’m really afraid of forgetting -_-!!!

Code:

function a($n){
$p = ($n+1) /2;                                                                                                                               use using using               ‐ ’ ’ s ‑       ‐ ‐ ‐ ‐ calculated for the middle line number
                                                                  to                                2*$i-1; //Upper half: number of * signs in each line
          $sp = ($n-$m)/2;                                                                                                                                                                                                                          Number
for ($ j = 1; $ j & lt; = $ sp; $ j ++) {echo "& nbsp;" ";} // space
for ($ j = 1; $ j & lt; = $ j ++) {echo "*";}                                                                             } Else {
if ($ i == $ p) {// Traversing the middle line: the number in the middle is just equal to the number of rows
for ($ j = 1; $ j & lt; = $ n; $ j ++) {echo "" "{echo" " "
                                                                                                           /*Number of numbers (regular-symmetrical)
                                                                                                                                                                                                                                                                                        echo " ";}                                                                                                                                                      for($j=1;$j< ;=$sp;$j++){echo " ";}                                                                                                                                                                                                       
}
}
a(9);
?>


Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.


The above introduces the PHP loop traversal of the inverted pyramid, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Object-oriented PHP (2)Next article:Object-oriented PHP (2)