Home >Backend Development >PHP Tutorial >How to use the for statement to output triangles in php_PHP tutorial
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:
?
2 3 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); ?> |