<p><code>assignUserToGroups</code> has <code>$groupIds</code> parameter (int / array) preset to <code>null</code>. From <a href="http://buildwithcraft.com/classreference/services/UserGroupsService#assignUserToGroups-detail" rel="nofollow">the docs</a>:</p>

<blockquote>
  <p><code>assignUserToGroups($userId, $groupIds = null)</code></p>
</blockquote>

<p>So calling the function without that parameter set should do it:</p>

<pre><code>craft()-&gt;userGroups-&gt;assignUserToGroups(1);
</code></pre>

CC BY-SA 3.0
2015-05-18T11:30:15.043Z
Ok thanks that does the job. Do you know if there is a way to remove the user from a specific group? Just forward thinking here. Cheers
Lettie
CC BY-SA 3.0
2015-05-18T11:32:38.993Z
Get all group IDs the user is assigned to and remove one group ID from that array, before passing it to `assignUserToGroups`.
carlcs
CC BY-SA 3.0
2015-05-18T11:35:49.950Z
That'll work cheers
Lettie
CC BY-SA 3.0
2015-05-18T11:22:32.193Z
2015-05-18T11:22:32.193Z
carlcs
<p>Ok this should be pretty simple I feel! But I can't find the documentation for it.</p>

<p>I can set assign a user to a user group within a plugin with:</p>

<pre><code>craft()-&gt;userGroups-&gt;assignUserToGroups($userid, $groupid);
</code></pre>

<p>How do I do the reverse and remove a user from a user group?</p>

<p>Cheers.</p>

<users><user-groups>
How to remove a user from a user group?
# How to remove a user from a user group?

(Asked by: username_0 on 2015-05-18)

Ok this should be pretty simple I feel! But I can't find the documentation for it.
I can set assign a user to a user group within a plugin with:
craft()->userGroups->assignUserToGroups($userid, $groupid);

How do I do the reverse and remove a user from a user group?
Cheers.

**Tags:** users, user-groups


---

## 1 answers

### Answer by username_1 on 2015-05-18. Score: 4 | Accepted answer

assignUserToGroups has $groupIds parameter (int / array) preset to null. From the docs:

assignUserToGroups($userId, $groupIds = null)

So calling the function without that parameter set should do it:
craft()->userGroups->assignUserToGroups(1);

> **Comments:**
> **username_0**: Ok thanks that does the job. Do you know if there is a way to remove the user from a specific group? Just forward thinking here. Cheers  
> **username_1**: Get all group IDs the user is assigned to and remove one group ID from that array, before passing it to `assignUserToGroups`.  
> **username_0**: That'll work cheers  

---

