PHP program to print Diamond Pattern

In this article write a PHP program to print Diamond Pattern using asterisk (*) symbol. We run for loop 8 times, in which you have two outer for loops which contains two nested for loops to print Pyramid Pattern and Reverse Pyramid Pattern of stars to print Diamond Star Pattern of stars as shown in the following program.

Program to print Diamond Pattern

echo "<pre>";
for ($i = 1; $i < 8; $i++) {
    for ($j = $i; $j < 8; $j++)
        echo "&nbsp;&nbsp;";
    for ($j = 2 * $i - 1; $j > 0; $j--)
        echo ("&nbsp;*");
    echo "<br>";
$n = 8;
for ($i = 8; $i > 0; $i--) {
    for ($j = $n - $i; $j > 0; $j--)
        echo "&nbsp;&nbsp;";
    for ($j = 2 * $i - 1; $j > 0; $j--)
        echo ("&nbsp;*");
    echo "<br>";
echo "</pre>";


diamond pattern

  1. Dheeraj Kumar says

    This is nice diamond program to php ….
    I am sure you would help to every one to the programming….
    I need to add delete search update ,
    And different type of pattern program in php,
    And more which you have updated and new program………

    1. Vikas Kumar says

      Hello Dheeraj Kumar,

      Thanks you like our blog post and yes sure i will add soon PHP pattern program.


Leave A Reply

Your email address will not be published.