This article describes the example of php using the for statement to output triangles. Share it with everyone for your reference. The specific implementation method is as follows:
<?php //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).'<br />'; } } Dis(19); ?>
I hope this article will be helpful to everyone’s PHP programming design.