How To Make The Number Triangle In Php ?

It is very easy to make a Number Triangle in php .This is a type of matrix in which we can print rows and columns .You can make the number triangle by using
(for loop) or (foreach) loop in php. For or foreach loop make it very easy in to make Number Triangle.This can improve the logic of Fresher . Check below the programming syntax in front
of output:.

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
<?php
for($i=0;$i<=7;$i++){
for($j=1;$j<=$i;$j++){
echo $j;
}
echo “<br>”;
} ?>
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
<?phpfor($i=0;$i<=7;$i++){
for($j=1;$j<=$i;$j++){
echo $i;
}
echo "<br>";
} ?>
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
<?phpfor($i=0;$i<=7;$i++){
for($j=1;$j<=$i;$j++){
echo "1";
}
echo "<br>";
} ?>
9 Comments

Leave a Reply