Code: Select all
foreach (range(1,10) as $num) {
echo($num.'<br />');
}Moderator: General Moderators
Code: Select all
foreach (range(1,10) as $num) {
echo($num.'<br />');
}Sorry it's taken me so long to reply. I just ran your test suite and these were my results.Robert Plank wrote:I guess it would be more fair if our code actually checked an array instead of counting up numbers.That's odd.. I just made a quick test suite
results:Code: Select all
test_ForeachWithIndice() 79.1614859104 seconds test_ForeachWithoutIndice() 69.2696409225 seconds test_For() 71.0619039536 seconds
Code: Select all
test_ForeachWithIndice() 75.1973428726 seconds
test_ForeachWithoutIndice() 70.8360300064 seconds
test_For() 66.339318037 secondsSeems like a waste of rescources, very minimal although but still not ideal in my books. You can hammer a nail with a sludge hammer -- or you can use the right tool for the job.CoderGoblin wrote:Personally when needing a for loop I tend to use a range...Code: Select all
foreach (range(1,10) as $num) { echo($num.'<br />'); }