[TASK] Performance: Avoid using array_keys in foreach

This lowers the memory usage.

Iterate on the original array instead of an array_keys()-copy
which lowers memory usage and enhances performance.

Change-Id: If65fae1665e242667d621f086a55a22a8d5309ed
Resolves: #64004
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/35373
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>