condition('name', $last_string, 'CONTAINS') ->execute(); $prefix = count($array) ? implode(', ', $array) . ', ' : ''; foreach ($aUserIds as $iUserId) { $oUser = user_load($iUserId); $matches[$prefix . $oUser->getDisplayName()] = $oUser->getDisplayName(); } return new JsonResponse($matches); } }