I want the following output using for loop in php -
i want display output
1 1 12 21 123 321 1234 4321 1234554321
here php code
for($i=1;$i <= 5;$i++) { for($j=1;$j<=$i;$j++) { // print result echo "$j"; } for($y=$i;$y<=$i;$y++) { echo ' '; } for($k=$i;$k>=1;$k--) { // print result echo " $k";} echo "<br/>"; }
but got output
1 1 12 2 1 123 3 2 1 1234 4 3 2 1 12345 5 4 3 2 1
please help me output above.
try
for($i=1;$i <= 5;$i++) { for($j=1;$j<=$i;$j++) { echo "$j"; } for($y=0;$y<(5-$i)*4;$y++) { echo ' '; } for($l=$i;$l>0;$l--) { echo "$l"; } echo "<br/>"; }
output:-
1 1 12 21 123 321 1234 4321 1234554321
for browser view :- for($y=0;$y<(5-$i)*4;$y++)
else right way going for($y=0;$y<(5-$i)*2;$y++)
php
No comments:
Post a Comment