I have a PHP array which has the set of users. Each user belongs to a team. The array would be looking like below.
$Array = ARRAY('User1', 'User2', 'User3', 'User4', 'User5');
I need to arrive the below logic.
If 'User1' and 'User2' belong to same team named 'Team1' and the other Users are having separate unique teams then the array should be reordered as below.
$Array = ARRAY('User1', 'User3', 'User4', 'User5', 'User2');
If 'User1' and 'User2' belong to same team named 'Team1' and 'User3' and 'User4' belong to same team named 'Team2' then array should reordered as below.
$Array = ARRAY('User1', 'User3', 'User5', 'User4', 'User2');
Number is users is dynamic and any user can have any team. The aim is to maximum avoid the Users from same team in subsequent places. It is better to keep Users from same team as far as we can.
I have tried many ways, but nothing works out. Please help me to arrive this logic. Please let me know if anybody need more info.
Thanks Ram