0
How can I make a circular loop using array?
I want to make a circular loop using array how can I do that can anyone help?
4 odpowiedzi
0
u want to say a circle
0
U need to use % by array length: so u lock 🔒 loop
0
As Eugene said, you can use modulus. Here is and example that will echo 0 to 9 ten times
for($i = 0; $i < 100; $i++) {
echo $i%10;
}
To reference an array you could echo myArray[$i]; inside the loop.
- 1
I suggest u take a look at circular queues of C++. Apply the same logic. Hope it helps