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