Get Groups from User in plugin Wondering if I can get user groups directly after retrieving the user via craft()-&gt;users-&gt;getUserById($id), or if i need to use craft()-&gt;userGroups-&gt;getGroupsByUserId($id) also?

As of right now, I'm looping through many users and want to check if they are in a specific group. A rough idea of what I'm looking at now:

// get user (necessary for rest of plugin)
$user = craft()-&gt;users-&gt;getUserById( $uid );

// get user groups
$user_groups = craft()-&gt;userGroups-&gt;getGroupsByUserId( $uid );

// check if user is in group
if( in_array("Group_Name", $user_groups) )
{
   // do something
}


This works, but when looping through a ton of users, I imagine it would be silly not to first check that I can already get this information from the $user variable I created. I can't seem to find the answer via documentation. Hoping to get a confirmation from someone!

Thanks
Your code to get a user returns a UserModel (as can be seen from the Full Class Reference docs):

$user = craft()-&gt;users-&gt;getUserById($id);


You can then get the user groups the $user is a member of usinggetGroups()(from the UserModel class):

$user_groups = $user-&gt;getGroups();