Memory usage of foreach

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'
method.

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
Daniel Klein [ Di, 08 April 2008 18:39 ] [ ID #1940529 ]

Re: Memory usage of foreach

http://jakarta.apache.org/jmeter/
Macca [ Di, 08 April 2008 22:42 ] [ ID #1940553 ]

Re: Memory usage of foreach

..oO(Daniel Klein)

>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'
>method.
>
>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?

http://php.net/memory_get_usage

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

Do you run into performance problems?

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

Micha
Michael Fesser [ Di, 08 April 2008 23:50 ] [ ID #1940557 ]
PHP » comp.lang.php » Memory usage of foreach

Vorheriges Thema: I am not able to see the executed output at all
Nächstes Thema: move_uploaded_file on localhost