Reputation: 67
I am new in PHP programming.Can anyone explain this code step by step?
for($i=1; $i<=5; $i++){
for($j=1; $j<=$i; $j++){
echo "*";
}
echo"<br>";
}
Upvotes: 0
Views: 1014
Reputation: 1470
The outer loop ($i) goes from 1 to 5. You can think of this as the rows of output in this case.
Within each row, the inner loop ($j) prints out a quantity of $i asterisks. So in row 1, it outputs *
, row 2, **
, and so on.
Before moving on to the next row, it prints out a line break. So the final output will be something like:
*
**
***
****
*****
Upvotes: 3