I think you misunderstood me..There's no need to globalize anything.
What I meant is basically this:

function loadMemberGroups()
{
$membergroups = array();
 /** query to fill $membergroups with data; **/
return $membergroups;
}

$context['membergroups'] = loadMemberGroups();