Hi guys I need to make a diamond like this for my lecturer,using nested for statements. I am having troubles. Can you guys give me any tips? ty.

Member Avatar for diafol

I'll give you a few pointers, but you don't need to nest anything.

rows = 9
increment/decrement amount = 2
symbol = *
(textalign = center - for layout)

With this info you can create any size of diamond, as long as the rows = odd number. Once you hit the middle value (5 in this case), you change the increment by 2 to decrement by 2. There are many, many ways to do this though.

 <?PHP
    $b = 1;
    for ($a=1; $a<=5; $a++)
    {
    echo str_repeat('*', $b);
    $b++;


    echo "<br>";
    }
    ?>
Member Avatar for diafol

^^ that won't produce a diamond - only a triangle. And ..

Can you guys give me any tips

So let's give him tips, not putative solutions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.