How To Make The Number Triangle Type-2 In Php ?
November 26, 2012
For the fresher it’s easy way to improve the logic and programming syntax. In php we can make the different types numerical triangle. Using for loop or foreach loop we can make a logic to show the triangle, Check below the programming syntax in front of out put:.
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 |
<?php for($i=0;$i<=7;$i++){ for($j=7-$i;$j>=1;$j--){ echo "1"; } echo "<br>"; } ?> |
7 6 5 4 3 2 1 6 5 4 3 2 1 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 |
<?php for($i=0;$i<=7;$i++){ for($j=7-$i;$j>=1;$j--){ echo $j; } echo "<br>"; } ?> |
7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 |
<?php for($i=7;$i>=1;$i--){ for($j=$i;$j>=1;$j--){ echo $i." "; } echo "<br>"; } ?> |
3 Comments
Great, thanks for sharing your knowledge. Really its very interesting and helpful.
Help mr please
54321
5432
543
54
5
Please try this code
=$i;$j–){
echo $j;
}
echo “<br>”;
}
?>