title: generate unique id for array value groups
body: <p>I have an asosiative array which contains data about teams and players. </p>
  
  <p>Example:</p>
  
  <pre><code>$arr = array(
    array('teamID'=&gt; '','teamName' =&gt; 'USA', 'playerName'='John'),
    array('teamID'=&gt; '','teamName' =&gt; 'USA', 'playerName'='Peter'),
    array('teamID'=&gt; '12','teamName' =&gt; 'Norway', 'playerName'='Zigmund'),
    array('teamID'=&gt; '','teamName' =&gt; 'USA', 'playerName'='Parker'),
    array('teamID'=&gt; '','teamName' =&gt; 'Norway', 'playerName'='Jan'),
    array('teamID'=&gt; '','teamName' =&gt; 'USA', 'playerName'='Hector'),
    array('teamID'=&gt; '','teamName' =&gt; 'Germany', 'playerName'='Alexander'),
    array('teamID'=&gt; '','teamName' =&gt; 'Slovakia', 'playerName'='Ivan')
  );
  </code></pre>
  
  <p>I want to generate unique ID for each team if it is not present, if the id is present for some team use it on same team names if they dont exist there, and do not use id's which already exists.</p>
  
  <p>What I have did is simple check if not exists ad index of the foreach loop, bet then it is per player not per team.</p>
  
  <p>Expected outcome: </p>
  
  <pre><code>$arr = array(
    array('teamID'=&gt; '1','teamName' =&gt; 'USA', 'playerName='John'),
    array('teamID'=&gt; '1','teamName' =&gt; 'USA', 'playerName'='Peter'),
    array('teamID'=&gt; '12','teamName' =&gt; 'Norway', 'playerName'='Zigmund'),
    array('teamID'=&gt; '1','teamName' =&gt; 'USA', 'playerName'='Parker'),
    array('teamID'=&gt; '12','teamName' =&gt; 'Norway', 'playerName'='Jan'),
    array('teamID'=&gt; '1','teamName' =&gt; 'USA', 'playerName'='Hector'),
    array('teamID'=&gt; '2','teamName' =&gt; 'Germany', 'playerName'='Alexander'),
    array('teamID'=&gt; '3','teamName' =&gt; 'Slovakia', 'playerName'='Ivan')    
  );
  </code></pre>
  
  <p>Any ideas on how to solve this?</p>