Programatically assigning multiple user role ? I am trying to assign multiple role while creating a user programatically. I am successfully creating a user and assigning one role using below code

$user = \Drupal\user\Entity\User::create();
// Mandatory.
$user-&gt;setPassword('111');
$user-&gt;enforceIsNew();
$user-&gt;setEmail('abcd@gmail.com');
$user-&gt;setUsername('abcd');
$user-&gt;addRole('lecturer');
$user-&gt;save();


I want to assign two roles during this code execution and tried the below code but it did not work

$user-&gt;addRole(['lecturer','program coodinator']);


How do I assign this?
If you look at User::addRole it says


  User::addRole($rid) 
  
  string $rid: The role ID to add.


Therefore, this cannot be an array. Thus, you must do this separate

$user-&gt;addRole('lecturer');
$user-&gt;addRole('program coodinator');
$user-&gt;save();


If you look at class User, there is no such thing as "addRoles" or any method that allows multiple way of doing it with an array.