How to make a numeric Polygon in PHP ?
We get the output of a numeric polygon using php ‘Loops’ with logic. Here we use eight Loops for print this diamond patterns in php.
– First and fifth are main and other are nested in these.
– First ‘Loop’ is used for number of lines in upper triangle and fifth Loop is used for number of lines in lower triangle.
– Second loop is used to print spaces, third loop is used for left side right angle triangle that will show counting according line number.
– Fourth loop is used for right side right angle triangle that will show reverse counting according to last line number.
– Sixth loop is used to print spaces and seventh is used to show counting in reverse order in lower left triangle (right angle triangle) and eighth is used to show counting 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=9; $z=9; for($i=1; $i<=$n; $i++) { for($j=$i; $j<=$n-1; $j++) { echo " "; } for($k=1; $k<=$m; $k++) { echo $k ." "; } for($c=$m; $c>1; $c--) { echo $c-1 ." "; } echo "<br>"; $m++; } for($i=1; $i<=$n; $i++) { for($j=1; $j<=$i; $j++) { echo " "; } for($k=1; $k<$z; $k++) { echo $k ." "; } for($c=$z-2; $c>=1; $c--){ echo $c ." "; } echo "<br>"; $z--; } ?> |
1 2 3 4
1 2 3
1 2
1
i need this output in php
Please try this code
=1; $a–){
for($b=1; $b<=$a; $b++){ echo $b;} echo "<br>"; } ?>
=1;$a –)
{
for($b=1; $b<=$a; $b++)
{
echo $b;
}
echo "”;
}
?>
Thank you i got many answers from this website and very interesting website to learn php from the beginning..