Created
July 10, 2014 15:01
-
-
Save caferrari/7164fb6bf2e2c10ea609 to your computer and use it in GitHub Desktop.
Amigo Secreto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function amigoSecreto(array $people) | |
{ | |
shuffle($people); | |
$temp = array(); | |
do { | |
array_push($temp, current($people), next($people)); | |
} while(current($people)); | |
array_splice($temp, -1, 1, [reset($temp)]); | |
return array_chunk($temp, 2); | |
} | |
$friends = amigoSecreto(["fulano", "ciclano", "beltrano", "zé"]); | |
print_r($friends); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment