Today I learned the most basic PHP conditions and looping statements, the last teacher raised a few questions, one of the implementation of the hollow pyramid image is more fun.
What the teacher wants us to achieve is:
*
* *
* * The Hollow pyramid.
First type:
Copy Code code as follows:
For ($i =1 $i <=5; $i + +) {
Switch ($i) {
Case 1:
echo "". " *"." ";
Break
Case 2:
echo "";
Break
Case 3:
echo "". " *"." "." *"." ";
Break
Case 4:
echo "";
Break
Case 5:
echo "*". " "." *"." "." *";
Break
}
echo "<br>";
The implementation of the effect is the teacher requested the image, but the teacher felt that there should be a more simple way to achieve, you can separate the space and the * number of output;
And then there's the second kind:
Copy Code code as follows:
For ($a =0 $a <4; $a + +) {
for ($b =4; $b > $a; $b-) {
echo "";
}
for ($c =1; $c <= $a; $c + +) {
echo "*";
}
for ($d =0; $d <= $a; $d + +) {
echo "*";
}
echo "<br>";
}
The effect of this implementation is not just the middle hollow, the effect is as follows:
*
***
*****
*******
This has not achieved hollow, will try again, today's first blog is completed, I hope that the future can be long written.