Jump to content

Recommended Posts

how can I increment a counter by 10 each time the loop passes?

 

EX:

$i = 10;

$i = 20;

etc

 

edited:

 

let me refine my question:

 

I want to make php sleep 1 second for every 100 loops.

 

code:

foreach( $array as $item ){

if($i == 100) sleep(1);

$i += 100

}

 

Link to comment
https://forums.phpfreaks.com/topic/139036-solved-probably-a-noob-question/
Share on other sites

Like this?

$i = 1;
foreach( $array as $item ){
   if($i == 100)
      sleep(1);
   $i++;
}

 

That should cause it to sleep 1 second for every 100 loops, incremented by $i.

 

Yea thats what I want but lets say you have 1000 keys in your array, but you don't know that because that array is generated dynamically in this case you would want the loop to sleep for a total of 10 seconds.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.