ballhogjoni Posted December 31, 2008 Share Posted December 31, 2008 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 More sharing options...
gwydionwaters Posted December 31, 2008 Share Posted December 31, 2008 $i=$i+10; Link to comment https://forums.phpfreaks.com/topic/139036-solved-probably-a-noob-question/#findComment-727193 Share on other sites More sharing options...
Zhadus Posted December 31, 2008 Share Posted December 31, 2008 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. Link to comment https://forums.phpfreaks.com/topic/139036-solved-probably-a-noob-question/#findComment-727201 Share on other sites More sharing options...
ballhogjoni Posted December 31, 2008 Author Share Posted December 31, 2008 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. Link to comment https://forums.phpfreaks.com/topic/139036-solved-probably-a-noob-question/#findComment-727203 Share on other sites More sharing options...
.josh Posted December 31, 2008 Share Posted December 31, 2008 Be more specific. That code sleeps 1 second for every 100 foreach loop iterations, regardless of how many elements there are in the array. What more do you want it to do? Link to comment https://forums.phpfreaks.com/topic/139036-solved-probably-a-noob-question/#findComment-727211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.