0

Is there a way to make a foreach loop increment by more than one? I am loading a jquery script before each item in a foreach loop and I want the delay to increase by 300 for each item, so that each item animates separately as opposed to at the same time.

So is there another method other than $i++? Like $i++ + 300? Or I am reaching a little too far on this one?


Thanks everyone for responding so quickly. The $i+=300 was exactly what I was looking for. I used this variable to increase the delay time on each of the scripts so it is executed one at a time on each item in the loop. Here is a link to what I used it for. Thanks again!

http://cloudninelabs.com/c9v10/portfolio/

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Ryan Sherman
  • 57
  • 1
  • 8
  • You tagged it with PHP, but it seems like you're talking about JavaScript. Which one is it? – shesek Aug 31 '11 at 00:28

3 Answers3

1

Basically you need to look after the counter yourself.

For example:

$i = 0;
foreach( $somelist as $index => $content ) {
     // Do something with $content using $i
     $i += 300;
}
staticsan
  • 29,935
  • 4
  • 60
  • 73
1

Are you looking for something like this:

foreach (array(1, 2, 3, 4) as &$value) {
    $value = $value + 300;
}
Sri
  • 405
  • 6
  • 16
0

Your question is kinda unclear to me, but it seems like you can simply use i*300 as your animation interval (e.g. foreach ($foo as $i => $bar) { /*simply use $i*300 as your interval here*/ })

However, just FIY, n a regular for loop you can use $i+=300 (e.g. for ($i=0; $i<10000; $i+=300). It doesn't make much sense to do anything like that in an foreach loop. Instead, keep a separate variable to keep track of that and increase that be 300 every time ($i=0; foreach ($foo as $bar) { ... $i+=300 }).

shesek
  • 4,584
  • 1
  • 28
  • 27