I have an asosiative array which contains data about teams and players.
Example:
$arr = array(
array('teamID'=> '','teamName' => 'USA', 'playerName'='John'),
array('teamID'=> '','teamName' => 'USA', 'playerName'='Peter'),
array('teamID'=> '12','teamName' => 'Norway', 'playerName'='Zigmund'),
array('teamID'=> '','teamName' => 'USA', 'playerName'='Parker'),
array('teamID'=> '','teamName' => 'Norway', 'playerName'='Jan'),
array('teamID'=> '','teamName' => 'USA', 'playerName'='Hector'),
array('teamID'=> '','teamName' => 'Germany', 'playerName'='Alexander'),
array('teamID'=> '','teamName' => 'Slovakia', 'playerName'='Ivan')
);
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.
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.
Expected outcome:
$arr = array(
array('teamID'=> '1','teamName' => 'USA', 'playerName='John'),
array('teamID'=> '1','teamName' => 'USA', 'playerName'='Peter'),
array('teamID'=> '12','teamName' => 'Norway', 'playerName'='Zigmund'),
array('teamID'=> '1','teamName' => 'USA', 'playerName'='Parker'),
array('teamID'=> '12','teamName' => 'Norway', 'playerName'='Jan'),
array('teamID'=> '1','teamName' => 'USA', 'playerName'='Hector'),
array('teamID'=> '2','teamName' => 'Germany', 'playerName'='Alexander'),
array('teamID'=> '3','teamName' => 'Slovakia', 'playerName'='Ivan')
);
Any ideas on how to solve this?