Example:
$atletas = array("A", "B", "C", "D", "E", "Bye", "Bye", "Bye");
My function:
function sortear_grelha($atletas) {
shuffle($atletas);
$atletas = array_chunk($atletas, 2);
return $atletas;
}
Expected result for example:
[["A","Bye"],["C","Bye"],["Bye","D"],["B","E"]]
The output I am getting:
[["A","Bye"],["Bye","Bye"],["C","D"],["B","E"]]
I want pairs of different values.
Here's one that works by calling
sortear_grelha()
recursively until there are no duplicates in a pair: