How can I create a pyramid from using php?

前端 未结 14 1246
耶瑟儿~
耶瑟儿~ 2020-12-11 08:58

I need to create a pyramid using asterisks. I specify a value which becomes the base of the pyramid. The base contains as much asterisks as the value specified and the pyram

14条回答
  •  半阙折子戏
    2020-12-11 09:30

    From what I understand, what you are looking for is an Odd numbered pyramid, i.e. the number of * in each row is as per odd number series, like 1,3,5,7. If you wish to include "if-else" statements then you can go with the above answered loops, but if you only wish to use "for" loops, then you can use the following code:

    $i;$j--)
              {
                echo '  ';
              }
          for($k=1;$k<=$x;$k++)
              {
                echo '*';
              }
              $x=$x+2;  
              echo "
    "; } ?>

提交回复
热议问题