Home > Backend Development > PHP Tutorial > How to use the for statement to output triangles in php_PHP tutorial

How to use the for statement to output triangles in php_PHP tutorial

WBOY
Release: 2016-07-13 09:51:29
Original
1242 people have browsed it

How PHP uses the for statement to output triangles

The example in this article describes how PHP uses the for statement to output triangles. 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

//phpinfo();

function Dis($num)

{

if($num<=0)

return;

$tmpRow=0;

for($i=1;$i<=$num;$i )

{

$tmpRow=$i<=$num/2 ? $i:$num-$i 1;

echo str_repeat('*',2*$tmpRow-1).'
';

}

}

Dis(19);

?>

1

2 3

45 6 7 8 9 10
11
12
13 14 15
<🎜>//phpinfo();<🎜> <🎜>function Dis($num)<🎜> <🎜>{<🎜> <🎜>if($num<=0)<🎜> <🎜>return;<🎜> <🎜>$tmpRow=0;<🎜> <🎜>for($i=1;$i<=$num;$i )<🎜> <🎜>{<🎜> <🎜>$tmpRow=$i<=$num/2 ? $i:$num-$i 1;<🎜> <🎜>echo str_repeat('*',2*$tmpRow-1).'
'; } } Dis(19); ?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/1013642.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1013642.htmlTechArticleHow to use the for statement to output triangles in php. This article describes how to use the for statement to output triangles in php. Share it with everyone for your reference. The specific implementation method is as follows: ? 1 2 3 4...
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