As you can see, the normal for loop takes less time than the Foreach loop when looping ArrayList;
when looping linklist, the normal for loop takes much more time than a foreach loop.
When I raise the number of cycles to 1 million times, the loop ArrayList, the normal for loop is a little faster than foreach;
But when the normal for loop linklist in the loop, the program dies directly.
need The data of the looping array structure is when used, it is recommended that normal for loop , because the for loop is accessed by subscript, For the data of the array structure, the use of subscript access is better.
need when looping the data of the linked list structure , , which is a bad practice and may cause the system to crash when the amount of data is large.
related recommendations:
php foreach and for statement usage differences Introduction _php tutorial