I use the foreach loop to process a large set of elements, unfortunately it uses a lot of memory. (probably because it makes a copy of the array). There seems to be a way to save some memory with the following code: $items = &$array;
Isn't it better to use for loops?
And is there any way to destroy every element as soon as they are processed in the foreach loop.
eg.
$items = &$array; foreach($items as $item) { dosomethingwithmy($item); destroy($item); }
I'm just looking for the best way to handle a large number of elements without running out of resources.
source share