for ($i=1; $i<=4; ++$i) {
echo "The number is " . $i . "\n";
}
This will output:
The number is 1
The number is 2
The number is 3
The number is 4
How can i make a loop that will give me output like so:
The number is 1
The number is 1
The number is 1
The number is 1
The number is 2
The number is 2
The number is 2
The number is 2
etc
Thanks for any help.
Essentially, you want to print something four times inside the loop… so you can write four echo statements. A better way to do this would be to use nested for loops.
For every iteration of the outer loop, the inner one prints the statement four times. One thing to be careful with nested loops is the variables used in the conditions. If you mix them up, you could have weird issues including an infinite loop.