diff --git a/group/index.php b/group/index.php
index 03314348025..6c3b7c41a39 100644
--- a/group/index.php
+++ b/group/index.php
@@ -323,9 +323,12 @@ if ($success) {
if (isset($userids)) { //&& is_array($userids)
// Put the groupings into a hash and sort them
$user_names = groups_userids_to_user_names($userids, $courseid);
-
- foreach ($user_names as $user) {
- echo "\n";
+ if(empty($user_names)) {
+ echo '';
+ } else {
+ foreach ($user_names as $user) {
+ echo "\n";
+ }
}
} else {
// Print an empty option to avoid the XHTML error of having an empty select element