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
.



Relevant Pages

  • Re: array Puzzle
    ... alfps@start.no (Alf P. Steinbach) wrote: ... > As a programming puzzle it's a bit more interesting (but still novice- ... > level) if memory usage is restricted to Oexcept the original array ... it requires modification of the original array. ...
    (comp.programming)
  • Re: FW: Array manipulation
    ... my %b = undef; ... foreach { ... Hmm,that will break the order of the original array. ... Jeff Pang ...
    (perl.beginners)