How to print user role id with dynamic variable of language? How to make this code dynamic  initially its printing only user role id for english language only ,if my current site having more then 10 to 20 languages how to change this code to dynamic           

         global $user; 
 global $language;
      //$lg =$language-&gt;language;
     dpm(user_load($user-&gt;uid));
    $user_fields = user_load($user-&gt;uid);
      //echo $user_fields-&gt;field_role['en'][0]['value'];

       $lg = $user_fields-&gt;language;
         //echo $lg;

     echo $user_fields-&gt;field_role['$lg'][0]['value'];


if i replace the ['en'] with ['$lg'] nothing is printing
You're using $lg inside single quotes ('), because of which PHP is considering it as static text. If you want to use variable inside quotes, use double quotes ("). Check this ans for more details.

Try below code, to print role based on language:

&lt;?php
global $user, $language;
$user_fields = user_load($user-&gt;uid);
// $lg = $user_fields-&gt;language;
$role = (!empty($user_fields-&gt;field_role[$language-&gt;language]) ? $user_fields-&gt;field_role[$language-&gt;language][0]['value'] : $user_fields-&gt;field_role['en'][0]['value'])
echo $role;
?&gt;