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!
array repetition
Moderator: General Moderators
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: array repetition
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.
But why would you want an infinite loop?
Code: Select all
$i = 0;
while (true) {
if ($i >= count($some_array)) $i = 0;
// do something with $some_array[$i]
$i++;
}-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: array repetition
You can also use foreach