-1

Our teacher in PHP is asking us to create a program where we would print a pyramid like figure, but what I'm really confused about is how do I print those asterisk by using loop or for. the other thing is how do i generate new size, by new size I mean for example:

the first figure would be 5x5, then if i refresh a page it would generate a new size like 11x11 or 7x7

if anyone would be be able to answer my question, i would be grateful.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 2
    Have you tried something yet? perhaps we can help you with your code. – briosheje Jul 24 '14 at 15:14
  • to be honest, i dont have any ideas about what to do, our teacher didn't give that much information, only a image of what it should look like, but sadly i can't post that image here since my reputation is low. – Lorenzo Carlo Naguit Jul 24 '14 at 16:22

1 Answers1

0

I posted an answer very similar to this already for Java. In PHP, the code is very similar:

<?php
    for($i = 0; $i <= 10; $i++)
    {
        for($j=0; $j<=$i; $j++)
        {
            echo "*";
        }
        echo "\n";
    }
?>

This will create a right triangle. If you want a pyramid, you should only slightly have to modify it, but I'll leave that part to you so I don't rob you of the learning experience.

Community
  • 1
  • 1
Alex W
  • 37,233
  • 13
  • 109
  • 109