Skip to content

Instantly share code, notes, and snippets.

@samhernandez
Last active December 20, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samhernandez/6143348 to your computer and use it in GitHub Desktop.
Save samhernandez/6143348 to your computer and use it in GitHub Desktop.
Get an array of users for a given role id.
/**
* Get an array of users for a given role id.
* @param int $rid - The role id
* @return array
*/
function users_by_role_id($rid)
{
$users = array();
$uids = array();
$query = db_query("SELECT uid FROM users_roles WHERE rid = :role_id", array(':role_id' => $rid));
while($uid = $query->fetchCol('uid')) {
$uids[] = $uid;
}
if ( ! empty($uids)) {
$users = user_load_multiple($uids);
}
return $users;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment