Memory usage of foreach

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Klein

    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
  • macca

    #2
    Re: Memory usage of foreach


    Comment

    • Michael Fesser

      #3
      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?
      Returns the amount of memory allocated to PHP

      >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

      Comment

      Working...