$s = chunk_split('0123456789',1);
$ar = split("[\r\n]+",$s);
array_pop($ar);
shuffle($ar);
return join('',array_slice($ar,rand(0,count($ar)-$len),$len));
}
2 个解决方案
#1
function foo($len=9) {
$s = chunk_split('0123456789',1);
$ar = explode(PHP_EOL,$s);
array_pop($ar);
shuffle($ar);
return join('',array_slice($ar,rand(0,count($ar)-$len),$len));
}
#2
function foo($len=9) {
$ar = str_split('0123456789',1);
shuffle($ar);
return join('',array_slice($ar,0,$len));
}
#1
function foo($len=9) {
$s = chunk_split('0123456789',1);
$ar = explode(PHP_EOL,$s);
array_pop($ar);
shuffle($ar);
return join('',array_slice($ar,rand(0,count($ar)-$len),$len));
}
#2
function foo($len=9) {
$ar = str_split('0123456789',1);
shuffle($ar);
return join('',array_slice($ar,0,$len));
}