array repetition

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shanehunter
Forum Commoner
Posts: 30
Joined: Sun Jun 27, 2010 3:43 pm

array repetition

Post 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!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: array repetition

Post 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?
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: array repetition

Post by internet-solution »

You can also use foreach
Post Reply