Page 1 of 1

array repetition

Posted: Wed Jul 07, 2010 5:09 pm
by shanehunter
Okay.

So i have an array

Shane
Tom
Terry
Bob
Bill

I want a $function to call up each value in this array one at a time, proceeding down the list from Shane ยป Bill

Once it hits Bill, the next time, I'd like it to jump back up to Shane, and make it's way down the list again in an infinite loop.

When my script is executed I want $function to display as a different value (in order) from the array each time.

ie: $function = 'Shane', $function = "Tom" etc.

Let me know. Appreciate the help!

Re: array repetition

Posted: Wed Jul 07, 2010 9:12 pm
by Jonah Bron
What do you mean by "call up each value"? What do you want it to do? If you just want to do something on each element infinitely, something like this would do.

Code: Select all

$i = 0;
while (true) {
    if ($i >= count($some_array)) $i = 0;
    // do something with $some_array[$i]
    $i++;
}
But why would you want an infinite loop?

Re: array repetition

Posted: Thu Jul 08, 2010 1:48 am
by internet-solution
You can also use foreach