0

I have an array that I need to continuously loop through until I get my outcome and then I will break the loop. I need to be able to start at a certain point of the array based on value of the string in the array.

Lets say I want to start on friday, then the continuous loop would start on friday and go from there before it stars over.

friday  //start here
saturday
sunday
monday
tuesday
wednesday
thursday
friday
...and so on

My Code

$array = array('monday','tuesday','wednesday','thursday','friday','saturday','sunday');

$infinate = new InfiniteIterator(new ArrayIterator($array));
foreach ($infinate as $key => $value) {
    //check stuff until I break the loop
}

Is this possible?

2
  • what value are you looking for in the array? Commented Jun 1, 2017 at 0:38
  • What is the backstory? What are you trying to accomplish/solve? Commented Jun 1, 2017 at 2:28

1 Answer 1

0
$start = 4;
    foreach (array_merge(array_slice($array, $start), array_slice($array, 0, 7)) as $key => $value){
       echo $value.'<br>';
    }

found something very similar to your problem here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.