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
Release: 2016-07-13 09:53:36
Original
1745 people have browsed it

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template