Second for loop is used to print spaces, third loop is used for left side right angle triangle that will show stars according line number and fourth loop is used for right side right angle triangle that will show stars according to last line number.
Sixth loop is used to print spaces and seventh is used to show stars in reverse order in lower left triangle(right angle triangle).
Eighth is used to show stars in reverse order in right side triangle(right angle triangle).
Here $n is used for number of lines in first loop and number of spaces in second loop.
syntax with output as below.
<?php $m=1; $n=5; for($i=1; $i<=5; $i++) { for($j=$i; $j<=4; $j++) { echo " "; }
for($k=1; $k<=$m; $k++) { echo "*"; }
for($c=$m; $c>1; $c--) { echo "*"; }
echo "<br>"; $m++; } for($i=1; $i<=5; $i++) { for($j=$i; $j>=1; $j--) { echo " "; } for($k=$n; $k>1; $k--) { echo "*"; } for($c=$n-1; $c>1; $c--)
{
echo "*"; }
echo "<br>"; $n--; } ?>
No comments:
Post a Comment