Discussions
for vs foreach php - which is good for array iteration
Posted by roy123 • 9/18/09 • Subscribe to this Discussion [RSS] • Report This Topic
Topics: for vs foreach php, php, php questions
Hi all php experts,
I am very curious to know whether for is goood or foreach is good to iterate over indexed array.
I mean if we want to iterate over integer indexed array then for is good or foreach is good.
And whats the case if we want to iterate over associate array??
User Comments
-
a for loop can be more optimized if you know the number of iterations ahead of time and optimize the count value. foreach is better with lists and is good for looping through each element in an array when you don't know the size.
-
Unless you are iterating over large arrays or have many levels of nested loops (which should be avoided anyway), you will probably not notice any speed difference.
Add Your Comment
Login to leave a message.




