This is much more difficult. I suggest copying players to another array. For example, for 3-4-3 formation, loop through the first array, searching players with "DF" role, copy them to another array, repeat this 3 times. Then do the same for "MD" players, repeat 4 times, then 3 times for "AT" players.
.
It would be easier without any arrays, if you had sprites for players. Add 18 instances of Player sprite, they can be just invisible rectangles. Define Role instance variable for each player. Then pick the first 3 "DF" players, add them to the team - set "IsInTeam=true" instance variable or something like that. Pick 4 "MD" players, add to the team. Pick 3 "AT" players, add to the team.