How to print star pattern in PHP?
In this post, we will create a star pattern in PHP that is usually asked by the
interviewer.
The main logic for asking this question by the interviewer is just to check
your loops knowledge.
So, Keeping these in mind, we have printed various possible star patterns in
PHP.
Star pattern in PHP
1. Star Pattern #1
* ** *** **** *****
<?php for($i=0; $i<=5; $i++) { for($j=1; $j<=$i; $j++) { echo "*"; } echo "
"; } ?>2. Star Pattern #2
***** **** *** ** *
<?php for($i=5; $i>=1; $i--) { for($j=0; $j<$i; $j++) { echo "*"; } echo "
"; } ?>
No comments: