I need to classify the user according to their role, so I need to find the user role by using the user_id alone (not only for logged in users but for all the BP users).
Something like this
Try this function:
I've not included any exception handling like whether the user exist or not, so you can do it yourself or in case you are getting the user ids list wont even be necessary.
I have created a function to get user role from userid.
call get_user_role() function to get the role of the user and pass the userid as parameter. It will return user role else will return false .