I want to loop from 1 till 5. That’s easy if you use a for loop:
for ($i=1; $i<=5; $i++)
{
// do something
}
But imagine instead of starting by $i=1 I have a random start number from 1 to 5 and this time its value is 3. So I have to start looping from 3 and the loop sequence should be: 3,4,5,1,2
I already have the radom number, let’s say it is 3, then I need 3 4 5 1 2 .. if it was 5, I would be needing 5 1 2 3 4
How can I do this??
Thanks a lot!
Try this :
You need two vars to do what you want. If you set J = 3, it’ll do 3 4 5 1 2
have fun.