$array[$term->getLanguageCode()] = $term->getText();

not

    $array[$term->getLanguageCode()] = $term;