PHP program to print Diamond Pattern

Program to print Diamond Pattern

<?php
for ($i = 1; $i < 6; $i++) {
    for ($j = $i; $j < 6; $j++)
        echo "&nbsp;&nbsp;";
    for ($j = 2 * $i - 1; $j > 0; $j--)
        echo ("&nbsp;*");
    echo "<br />";
}
$n = 6;
for ($i = 6; $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 />";
}
?>

Output:

           *
         * * *
       * * * * *
     * * * * * * *
   * * * * * * * * *
 * * * * * * * * * * *
   * * * * * * * * *
     * * * * * * *
       * * * * *
         * * *
           *
Leave a reply
Captcha Click on image to update the captcha .