assigning a role to a user programatically I have been looking around for how to assign a role to a user programatically and there is some discussion. Basing my code a little off of https://drupal.org/node/28379, will this work?


    global $user;
    $myuser = user_load($user->uid); 
    $myuser->$role[4] = 'Member';
    user_save($myuser); 


where I already know that the Member role is stored at key 4 (I did a print_r on user who is assigned that role and I see

 [roles] =&gt; Array ( [2] =&gt; authenticated user [4] =&gt; Member )
$uid = 123;// User ID of user that you want to add role to.
$role_name = 'Role to add'; // The name of the role to add.
if ($role = user_role_load_by_name($role_name)) {
  user_multiple_role_edit(array($uid), 'add_role', $role-&gt;rid);
}


Is how you should do it in Drupal 7. See https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_multiple_role_edit/7