Print Star Pattern in PHP

Advertisements

Prev Tutorial Next Tutorial

Print Triangle of Stars in PHP

This is not new concept, you need to follow same concept like C programming to print star pattern or triangle of star.

Print Star Pattern in PHP

<?php

for ($row = 1; $row <= 5; $row++)
{
 echo "* </br>";
}

?>

Output

	
*
*
*
*
*

Print Triangle of Stars in PHP

<?php

for ($row = 1; $row <= 5; $row++)
{
 for ($col = 1; $col <= 5; $col++)
  {
   echo '* ';
  }
   echo "</br>";
}

?>

Output

	
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

Print Star Pattern in PHP

<?php

for($i=0;$i<=5;$i++)
{
for($j=0;$j<=$i;$j++)
{
echo "* ";
}
echo "<br>";
}

?>

Output

	
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *

Print Star Pattern in PHP

<?php

for($i=0;$i<=5;$i++)
{
for($j=5-$i;$j>=1;$j--)
{
echo "* ";
}
echo "<br>";
}

?>

Output

	
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

Print Triangle of Stars in PHP

<?php

for($a=5; $a>=1; $a--)
{
if($a%2 != 0)
{
for($b=5; $b>=$a; $b--)
{
echo "* ";
}
echo "<br>";
}
}
for($a=2; $a<=5; $a++)
{
 if($a%2 != 0)
{
 for($b=5; $b>=$a; $b--)
{
echo "* ";
}
echo "<br>";
}
}

?>

Output

	
*
* * *
* * * * *
* * *
* 

Print Star Pattern in PHP

<?php
for ($row = 1; $row <= 5; $row++)
{
    for ($col = 1; $col <= ($row > 3 ? 6 - $row : $row); $col++)
    {
        echo '* ';
    }

     echo "</br>";
}

?>

Output

	
*
* *
* * *
* *
*

Print Triangle of Stars in PHP

<?php

for($i=0;$i<=6;$i++)
{
for($k=6;$k>=$i;$k--)
{
echo "  ";
}
for($j=1;$j<=$i;$j++)
{
echo "*  ";
}
echo "<br>";
}
for($i=5;$i>=1;$i--)
{
for($k=6;$k>=$i;$k--)
{
echo "  ";
}
for($j=1;$j<=$i;$j++)
{
echo "*  ";
}
echo "<br>";
}

?>

Output

	
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements