Home >Backend Development >PHP Tutorial >How to output an isosceles triangle in PHP_PHP tutorial

How to output an isosceles triangle in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:53:361743browse

How to output an isosceles triangle in PHP

This article explains how to output an isosceles triangle in PHP. Share it with everyone 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."
";

}

}

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);

1

2

3

4

5

6

7

8

9

1011 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."
"; } } 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 results are as follows: ใ€€====*==== ===***=== ใ€€==*****== ใ€€=*******= ************ I hope this article will be helpful to everyoneโ€™s PHP programming design. http://www.bkjia.com/PHPjc/1000120.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1000120.htmlTechArticleHow to output an isosceles triangle in PHP. This article describes how to output an isosceles triangle in PHP. Share it with everyone for your reference. The specific implementation method is as follows: ? 1 2 3 4 5 6 7...
Statement๏ผš
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn