I want to make a loop that will take $x and add one for $n times, printing the result for each one, and using the previous result for the next.
so if $n=4 and $x=1
2
3
4
5
how in the world could i do this?
simple math
Moderator: General Moderators
There's a few ways, you could use a for() loop for example, or here's another way.
Code: Select all
$x=1;
$n=4;
echo join('<br />', range($x+1, $x+$n));Code: Select all
// for loop version
$x = 1;
$n = 4;
for ($i = 0; $i < $n; $i++) {
$x += 1; // same as $x = $x + 1;
echo "$x<br />";
}-
Daisy Cutter
- Forum Commoner
- Posts: 75
- Joined: Sun Aug 01, 2004 9:51 am
this is more simple, but maybe its all you need :
Code: Select all
for ($i = 2; $i <= 5; $i++) {
echo $i;
}