There are two fields to check. One is $userdata['user_level'] which will tell you if the user is an admin or not. Note that admin level is board wide; if a user is an admin, they are an admin everywhere. There is another user_level value for moderators, but it cannot be trusted. A user can be a moderator in one forum and not another. To generate the correct setting for a user being a moderator you should check the "auth" results.
The user rank, which shows the user's rank title (often something like "newbie" or "mega poster" or "spammer"

) is determined by one of two things. There is a field called user_rank that is normally zero, at which point the user's rank is assigned based on their post count. If the user_rank is a non-zero value, then the rank title is retrieved from the phpbb_ranks table. There is some rather complicated logic in viewtopic.php that shows how the rank title is assigned.
Since you're looking for coding tips, I will move your post to the phpBB2 MOD Writers forum for further attention, thanks.