Home >Backend Development >PHP Tutorial >How to output an isosceles triangle in PHP, PHP outputs an isosceles triangle_PHP tutorial
The example in 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:
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."<br>"; } } 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.