Hi friend, hope you are doing good. In this tutorial, we will let you know how to print triangle of stars in PHP programming language.
Copy the below code and create a new PHP file and paste, after that execute that file with the help of PHP compiler to see the output.
1 2 3 4 5 6 7 8 9 10 11 12 | <?php for($i=0;$i<=5;$i++) { for($j=0;$j<=$i;$j++) { echo "* "; } echo "<br>"; } ?> |
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
Below PHP program will print the star pattern in reverse order.
1 2 3 4 5 6 7 8 9 10 11 12 | <?php for($i=0;$i<=5;$i++) { for($j=5-$i;$j>=1;$j--) { echo "* "; } echo "<br>"; } ?> |
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.