*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
<?php
for ($i=1; $i <=6; $i++) {
# code...
echo "*";
for ($j=1; $j <$i ; $j++) {
# code...
echo "*";
}
echo "<br>";
}
for ($i=5;$i >=1; $i--) {
# code...
echo "*";
for ($j=1; $j < $i; $j++) {
# code...
echo "*";
}
echo "<br>";
}
?>
This out put is print pyramid In PHP .This code is using for loop to print out put it print good output.
in this program main two for loop are there and inside one loop one more sub for loop are there.
First for loop is print upper first 6 line, as * and i will work as start to 1 and goes to 6 and increment to as 6. inside sub for loop is print start form 1 and goes to last as $i value for main loop also it increment. and print as * .
Second For loop is print last 5 line as * and it will work as start from 5 and goes to 1 it will decrements as 1.inside the sub for loop it also start form 1 and last as $i value of main loop.
Finally it will print above output using 4 for loop 2 are main and 2 are Sub for loop.
Vips The Dev
Thanks,.
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
<?php
for ($i=1; $i <=6; $i++) {
# code...
echo "*";
for ($j=1; $j <$i ; $j++) {
# code...
echo "*";
}
echo "<br>";
}
for ($i=5;$i >=1; $i--) {
# code...
echo "*";
for ($j=1; $j < $i; $j++) {
# code...
echo "*";
}
echo "<br>";
}
?>
This out put is print pyramid In PHP .This code is using for loop to print out put it print good output.
in this program main two for loop are there and inside one loop one more sub for loop are there.
First for loop is print upper first 6 line, as * and i will work as start to 1 and goes to 6 and increment to as 6. inside sub for loop is print start form 1 and goes to last as $i value for main loop also it increment. and print as * .
Second For loop is print last 5 line as * and it will work as start from 5 and goes to 1 it will decrements as 1.inside the sub for loop it also start form 1 and last as $i value of main loop.
Finally it will print above output using 4 for loop 2 are main and 2 are Sub for loop.
Vips The Dev
Thanks,.
Comments
Post a Comment