According to HHVM inconsistencies guildline, "Under Zend PHP, foreach by value will modify the array's internal cursor under certain circumstances. Under HipHop VM, foreach by value will never modify the array's internal cursor.
Moving end() from above key() function to below it also make the code easier to understand as the behavior of foreach with array cursor is complicated to understand.
JoomlaCode Tracker Item: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33412&start=0