How to make star triangle in php

We can make star triangle very easily by using ‘for’ loop in php. It helps to improve the logic of a php beginner. A star triangle/star pyramid looks like below:

 

star triangle     OR       star pyramid

 

If you want output like 1st picture, write a sample code in php like below:

 

<p align="center">
<?php

for($i=7;$i>0;$i--){
for($j=0;$j<$i;$j++){
echo "*";
}
echo "<br>";
}

?>
</p>


If you want output like 2nd picture, write a sample code in php like below:

 
<p align="center">
<?php

for($i=1;$i<=7;$i++){
for($j=0;$j<$i;$j++){
echo "*";
}
echo "<br>";
}

?>
</p>