Memory usage of foreach

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I read somewhere that 'foreach' iterates over a 'copy' of the array, whereas
doing something like:

while (list($key, $value) = each($myarray))

iterates over the original array. Up til now, I've been using the 'foreach'

If this is true then I'm concerned about memory usage as some of the arrays
I'm working on can grow fairly large.

Is it possible to check memory usage of your php program?

I may be converting code over to the list() method. What are the caveats of
doing this?

Daniel Klein

Re: Memory usage of foreach /

Re: Memory usage of foreach

.oO(Daniel Klein)

Quoted text here. Click to load it

Quoted text here. Click to load it

Do you run into performance problems?

Google "premature optimization" and use a profiler to find the real
bottlenecks in your code.


Site Timeline