How can I create a pyramid from using php?

前端 未结 14 1255
耶瑟儿~
耶瑟儿~ 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:22

    function pyramid($height)
    {
    
        for ($i = 1; $i <= $height; $i++) {
            echo str_repeat("  ", $height - $i);
            echo str_repeat('*', $i * 2 - 1) . '
    '; } } pyramid(5);

提交回复
热议问题