Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Pattern Desigining in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 164
    Comment on it

    Hello Reader! All of us must have designed a code to print pyramid or some other pattern of asterisk using C, C++. Here is a simple program to print the different asterisk(stars) patterns in PHP. A pattern of stars is a way of arranging these in some logical manner or they may form a sequence.

    /*Program to draw a pattern of asterisk using PHP */

    1. <?php
    2.     echo "Pattern 1:<br>";
    3.     for ($i=0; $i <5 ; $i++)
    4.     {
    5.         for ($j=1; $j <5-$i ; $j++)
    6.         {
    7.             echo "&nbsp;&nbsp ";
    8.         }
    9.         for ($k=0; $k <=$i ; $k++)
    10.         {
    11.             echo "* ";
    12.         }
    13.         echo "<br>";
    14.     }
    15.     echo "Pattern 2:<br>";
    16.     for ($i=1; $i <=4 ; $i++)
    17.     {
    18.         for ($j=$i; $j < 4; $j++)
    19.         {
    20.             echo "&nbsp ";
    21.         }
    22.         for ($k=1; $k <($i*2) ; $k++)
    23.         {
    24.             echo "* ";
    25.         }
    26.         echo "<br>";
    27.     }
    28.     echo "Pattern 3:<br>";
    29.     for ($i=1; $i <=6 ; $i++)
    30.     {
    31.         for ($j=6; $j >=1 ; $j--)
    32.         {
    33.             if ($i==$j)
    34.             {
    35.                 echo " * ";
    36.             }
    37.             else
    38.             {
    39.                 echo " &nbsp;";
    40.             }
    41.         }
    42.         for ($k=2; $k <=6 ; $k++)
    43.         {
    44.             if ($i==$k)
    45.             {
    46.                 echo " * ";
    47.             }
    48.             else
    49.             {
    50.                 echo " &nbsp;";
    51.             }
    52.         }
    53.         echo "<br>";
    54.     }
    55.     echo "Pattern 4:<br>";
    56.     for ($i=1; $i <=6 ; $i++)
    57.     {
    58.         for ($j=6; $j >=1 ; $j--)
    59.         {
    60.             if ($i==$j)
    61.             {
    62.                 echo " * ";
    63.             }
    64.             else
    65.              {
    66.                 echo " &nbsp;";
    67.             }
    68.         }
    69.         echo "<br>";
    70.     }
    71.     echo "Pattern 5:<br>";
    72.     for ($i=1; $i <=6 ; $i++)
    73.     {
    74.         for ($j=1; $j <=6 ; $j++)
    75.         {
    76.             if ($i==$j)
    77.             {
    78.                 echo " * ";
    79.             }
    80.             else
    81.             {
    82.                 echo " &nbsp;";
    83.             }
    84.         }
    85.         echo "<br>";
    86.     }
    87. ?>
    88.  

    click here for output

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: