title: Getting Joomla User Group Id to variable
body: <p>Joomla 3.0</p>
  
  <pre><code>$user = JFactory::getUser();
  $groups = $user-&gt;get('groups');
  
  foreach($groups as $group) {
  echo $group;
  }
  </code></pre>
  
  <p>This was an answer @lodder gave a while back, in regards to getting the user group id. My issue is that the user is in multiple groups. I need to differentiates between using the second group that gets ran. For example. </p>
  
  <p>User 1 = Group 2 &amp; 11</p>
  
  <p>User 2 = Group 2 &amp; 14</p>
  
  <p>User 3 = Group 2 &amp; 16</p>
  
  <p>How can i get this into a variable I can use. I'm having a duhhh....moment...</p>
  
  <p>I feel like this should actually be called by using something more like this</p>
  
  <pre><code>$user = JFactory::getUser();
  $groups = $user-&gt;get('groups');
  
  $usergrouptwo = $groups[2];
  </code></pre>
  
  <p>Then again, I have more experiance with for() loops than foreach loops.</p>
  
  <p>I need to simply be able to use a variable outside of the foreach() like this</p>
  
  <pre><code>If ($finalgroupid = 11) Do X
  If ($finalgroupid = 14) Do Y
  If ($finalgroupid = 16) Do Z
  </code></pre>
  
  <p>Again, I'm sure their is something stupid I'm forgetting. </p>
  
  <p>Thanks in advance for your help!</p>