Skip to content

Instantly share code, notes, and snippets.

@axgle
Created May 8, 2014 06:18
Show Gist options
  • Save axgle/607e811ed1f167f82472 to your computer and use it in GitHub Desktop.
Save axgle/607e811ed1f167f82472 to your computer and use it in GitHub Desktop.
<?php
// http://www.php.net/shuffle
//http://www.cnblogs.com/Jerry-Chou/archive/2012/01/04/2311610.html
function sh($arr){
$n=count($arr);
while($n>1){
$n--;
$k=rand(0,$n);
$tmp=$arr[$n];
$arr[$n]=$arr[$k];
$arr[$k]=$tmp;
}
}
$arr=array(1,2,3,4);
sh(&$arr);
print_r($arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment