Print Star Pattern in PHP
Today we will learn about how to Pint Star pattern in php. Here simple pattern is given below.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Print Triangle of Stars in PHP
<?php
for($i=0;$i<=4;$i++)
{
for($k=4;$k>=$i;$k–)
{
echo " ";
}
for($j=1;$j< =$i;$j++)
{
echo "* ";
}
echo " ";
}
for($i=3;$i>=1;$i–)
{
for($k=4;$k>=$i;$k–)
{
echo " ";
}
for($j=1;$j< =$i;$j++)
{
echo "* ";
}
echo " ";
}
?>
Print Below Pattern
*
***
****
***
*
Example for print star pattern
< ?php
$s="*"; for($a=5; $a>=1; $a–)
{
if($a%2 != 0)
{
for($b=5; $b>=$a; $b–)
{
echo $s;
}
echo "<br>";
}
}
for($a=2; $a< =5; $a++)
{
if($a%2 != 0)
{
for($b=5; $b>=$a; $b–)
{
echo $s;
}
echo "<br>";
}
}
?>
No comments :
Post a Comment