PHP Method for outputting an isosceles triangle
This example describes how PHP outputs an isosceles triangle. Share it with you for your reference. The specific implementation method is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
Function isosceles ($ line, $ sing ){ $ Tab = '; For ($ I = 1; $ I <$ line + 1; $ I ++ ){ $ Blank = print_blank ($ I, $ line, $ tab ); $ Code = print_code ($ I, $ sing ); Echo $ blank. $ code. $ blank. "<br> "; } } Function print_blank ($ num, $ line, $ tab ){ $ Blank = ''; For ($ I = $ num; $ I <$ line; $ I ++ ){ $ Blank. = $ tab; } Return $ blank; } Function print_code ($ num, $ sing ){ $ Code = ''; For ($ I = 0; $ I <(2 * ($ num-1) + 1); $ I ++ ){ $ Code. = $ sing; } Return $ code; } $ Line = 5; $ Sing = "*"; Isosceles ($ line, $ sing ); |
The running result is as follows:
==== * ====
===*** =
= ***** =
= ******* =
*********
I hope this article will help you with php programming.