You have to look through each user (filtering by flags if needed), and see if there user record has certain information. If so, reacord the user and return the list if needed.
If you do it often, you can optimize it by storing the positions in a global array. Then all you have to do is $positions($pos) to get the handle.
It all depends how often you do it. If you only have a few users, it won't make a difference anyway. If you have thousands of users, it may be a good idea.