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
    • 162
    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 */

    <?php
    	echo "Pattern 1:<br>";
    	for ($i=0; $i <5 ; $i++)
    	{ 
    		for ($j=1; $j <5-$i ; $j++)
    		{ 
    			echo "&nbsp;&nbsp ";
    		}
    		for ($k=0; $k <=$i ; $k++)
    		{ 
    			echo "* ";
    		}
    		echo "<br>";
    	}
    	echo "Pattern 2:<br>";
    	for ($i=1; $i <=4 ; $i++)
    	{ 
    		for ($j=$i; $j < 4; $j++)
    		{
    			echo "&nbsp ";
    		}
    		for ($k=1; $k <($i*2) ; $k++)
    		{ 
    			echo "* ";
    		}
    		echo "<br>";
    	}
    	echo "Pattern 3:<br>";
    	for ($i=1; $i <=6 ; $i++)
    	{ 
    		for ($j=6; $j >=1 ; $j--)
    		{ 
    			if ($i==$j)
    			{
    				echo " * ";
    			}
    			else
    			{
    				echo " &nbsp;";
    			}
    		}
    		for ($k=2; $k <=6 ; $k++)
    		{ 
    			if ($i==$k)
    			{
    				echo " * ";
    			}
    			else
    			{
    				echo " &nbsp;";
    			}
    		}
    		echo "<br>";
    	}
    	echo "Pattern 4:<br>";
    	for ($i=1; $i <=6 ; $i++)
    	{ 
    		for ($j=6; $j >=1 ; $j--)
    		{ 
    			if ($i==$j)
    			{
    				echo " * ";
    			}
    			else
    		 	{
    				echo " &nbsp;";
    			}
    		}
    		echo "<br>";
    	}
    	echo "Pattern 5:<br>";
    	for ($i=1; $i <=6 ; $i++)
    	{ 
    		for ($j=1; $j <=6 ; $j++)
    		{ 
    			if ($i==$j)
    			{
    				echo " * ";
    			}
    			else
    			{
    				echo " &nbsp;";
    			}
    		}
    		echo "<br>";
    	}
    ?>
    

    click here for output

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: