There is an array with names, for example:
$donalds_nephews = array('Huey', 'Dewey', 'Louie');
array
(
[0] => Huey
[1] => Dewey
[2] => Louie
)
I want to shuffle this array, but ensure that no value of the original array has the same key as the shuffled one.
$donalds_nephews_shuffled = shuffle($donalds_nephews);
This could result in 6 possible permutations:
- Huey, Dewey, Louie
- Huey, Louie, Dewey
- Dewey, Louie, Huey
- Dewey, Huey, Louie
- Louie, Dewey, Huey
- Louie, Huey, Dewey
1st, 2nd, 4th and 5th must not be the result.
What's the best way to do so? It's for Secret Santa.