This article mainly introduces the pyramid chart implemented by loops in PHP. This article is a PHP class note, which summarizes the instructor's homework, for more information, see the basic PHP conditions and loop statements learned today. Finally, the teacher asked a few questions, one of which is more fun to implement the hollow pyramid.
What the teacher wants us to achieve is:
*
**
.
First:
The code is 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"
";
The implementation effect is the image requested by the teacher, but the teacher thinks there should be a simpler implementation method, which can separate the space and the * number;
So there is the second type:
The code is 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"
";
}
The effect of this implementation is not as hollow as it was just now. The effect is as follows:
*
***
*****
*******
This is not implemented yet. I will try again later. Today, the first blog is completed, and I hope it can be written for a long time.