views:

97

answers:

2
$values = array(...);
foreach($values as $value) {
    // do something
}

How to run each $value after finishing the previous?

Thanks.

+6  A: 

As far as I can tell, this loop does exactly what you want it to. The iterations don't all start at the same time; they are run in the order of the elements of the $values array.

Thomas
second that notion
Orbit
+7  A: 

How exactly do you mean? foreach ist working one value after the other. You can easily proof that with something like that:

$values = array(1, 2, 3, 4, 5);
foreach($values as $value){
  echo 'Working on value '.$value.'<br />\n';
  echo 'Finished working on value '.$value.'<br />\n';
}

Or did I miss something there?

sprain
@IgnatzIt's not a solution because there is no problem. I just tried to show that you are actually already doing what you want to do.
sprain
Seems people today are too angry, give so many minuses.
Happy
We're not angry; we're downvoting because we can't understand what you want in your question.
BoltClock
@Ignatz: People are not angry, but you made your question such way, you should clarify your question, variables can not run, do variable doesn't make sense.
Sarfraz
@BoltClock maybe this just a newbie question, you can give a simple answer.
Happy
@Ignatz: I don't have to. This answer is as simple as it gets.
BoltClock
@Ignatz Glad it helped. Don't worry about the minuses. You just understood a very basic element of php programming. That's a good thing and will help you make further progress.
sprain
@sprain your answer made me smiling, thanks man.
Happy
@lgnatz I think people are giving the minuses becaue they're used to seeing questions that are more thorough and descriptive. But hey, we all have to start somewhere, and we were all at that point at some stage in our development careers. Hey man, not to worry, so you learn, now go out there and become a kicka@# developer!
webfac