How to make pyramid in PHP ?’

Code
<?php
$n=5;
for($i=0;$i<=$n;$i++)
{
for($j=0;$j<=$i;$j++)
print(“*”);
print(“<br/>”);
}
?>

Output

Code
<?php
$n=5;
for($i=0;$i<=$n;$i++)
{
for($j=0;$j<=$n-$i;$j++)
print(“*”);
print(“<br/>”);
}
?>

Output

Code

<?php
$n=5;
$k=$n;
for($i=0;$i<$n;$i++)
{
for($j=0;$j<=$k;$j++)
print(“&nbsp;”);
$k–;
for($j=0;$j<=$i;$j++)
print(“*”);
print(“<br/>”);
}
?>
Output

Code
<?php
$n=5;
$z=$n;
for($i=0;$i<=$n;$i++)
{
for($j=0;$j<=$i;$j++)
print(“&nbsp;”);
for($j=0;$j<=$z;$j++)
print(“*”);
$z–;
print(“<br/>”);
}
?>

Output

Code
<?php
$n=5;
$k=$n;
$z=$n;
for($i=0;$i<$n;$i++)
{
for($j=0;$j<=$k;$j++)
print(“&nbsp;”);
$k–;
for($j=0;$j<=$i;$j++)
print(“*”);
print(“<br/>”);
}
for($i=0;$i<=$n;$i++)
{
for($j=0;$j<=$i;$j++)
print(“&nbsp;”);
for($j=0;$j<=$z;$j++)
print(“*”);
$z–;
print(“<br/>”);
}
?>
Output

If found any error in above program try this file to run .
Click here to download

Leave a Reply