How To Make The Number Triangle In Php ?
November 26, 2012
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
AAAAA
BBBB
CCC
DD
E
how to print….??????
for( $a=1; $a=$a; $b–){
echo (chr(64+$a));
}
echo “”;
}
for( $a=1; $a=$a; $b–){
echo (chr(64+$a));
}
echo “”;
}
Yes, you are right Faiza,
we can print the Alphabets using other methods please check here.
http://www.powerfaq.com/how-to-print-alphabet-series-in-php
Faiza, Your method is not correct. It’s making the loop infinite. Please check your method and describe the condition $a=$a; $b-
{echo”aaaaa”
}
{
echo”bbbb”
}
{echo”ccc”
}
{echo”bb”}
{
echp”a”}
how to print
#####*
####**
###***
##****
#*****
how to print code php
#
# #
# #
# #
# # # # #
<?php
for($i=1;$i<=4;$i++){
for($j=1;$j<$i;$j++){
echo $j;
}
echo $i.'’;
}
?>