Last active
December 20, 2015 13:59
-
-
Save samhernandez/6143348 to your computer and use it in GitHub Desktop.
Get an array of users for a given role id.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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