Arrays memory management / SplFixedArray iteration / foreach array copy

426 Views Asked by At

As I know foreach construction does not operate on the array itself, but rather on a copy of it.

You can avoid copy of array by using following construction:

reset($array);
while (list($key, $value) = each($array)) {
  echo "$key is $value<br>\n";
}

The question is when I create fixed array with:

$fixedArrayObj = new SplFixedArray(5);

and then iterating it with foreach construction - does it creates copy of array and I should still stick to 'while/each' method to avoid it?

0

There are 0 best solutions below