diff --git a/lib/datalib.php b/lib/datalib.php
index <HASH>..<HASH> 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -2019,7 +2019,7 @@ function get_group_teachers($courseid, $groupid) {
             if (($teacher->authority > 0) and ismember($groupid, $teacher->id)) {  // Specific group teachers
                 continue;
             }
-            unset($teacher[$key]);
+            unset($teachers[$key]);
         }
     }
     return $teachers;
fixed bug <I>, thanks Ilshat Fattakhov; merged from MOODLE_<I>_STABLE