Created
December 10, 2014 20:50
-
-
Save pwaldhauer/4fef8ca0875ac0acd18d to your computer and use it in GitHub Desktop.
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 array_swap(&$array,$swap_a,$swap_b){ | |
list($array[$swap_a],$array[$swap_b]) = array($array[$swap_b],$array[$swap_a]); | |
} | |
$zwerge = [5, 5, 5, 5, 5, 8, 8, 8, 8, 8]; | |
shuffle($zwerge); | |
print_r($zwerge); | |
for($i = 0; $i < count($zwerge) - 1; $i++) { | |
$self = $zwerge[$i]; | |
for($o = 1; $o < count($zwerge) - 1; $o++) { | |
$first = $zwerge[$o]; | |
$second = $zwerge[$o+1]; | |
if($first != $second) { | |
array_swap($zwerge, $o + 1, $i); | |
break 1; | |
} | |
} | |
} | |
echo "done\n"; | |
print_r($zwerge); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment