This function, which is relied on by user_group and get_groups, returns a list of group objects that correspond to the group ID array given. All fine except that the array is just indexed 0,1, etc. but it should be indexed by group ID.
Some usages of get_groups etc in legacy code (we noticed one in quiz results) rely on the array keys being IDs so these probably don't work at present. It might need more checking to ensure this is the expected behaviour throughout, but otherwise this fix should be checked in.