Resolves MDL-45997

Up until now, older Moodle code used reference semantics in foreach loops which are illegal as of PHP 5.2. This patch replaces these operations with equivalent PHP 5.2+ ones, allowing better compatibility between Moodle and modern PHP runtimes.

Issue addressed: https://tracker.moodle.org/browse/MDL-45997