标签:fun each code else ret for count gre cti
$c = [12,13,11,10,4,1,5,56,87,45,332,123,4414,1312];
function sortBy($c)
{
if (count($c) < 2) {
return $c;
}else {
$d = $c[0];
$less = [];
$great = [];
foreach ($c as $value) {
if ($value < $d) {
$less[] = $value;
}
if ($value > $d){
$great[] = $value;
}
}
return array_merge(sortBy($less),[$d],sortBy($great));
}
}
var_dump(sortBy($c));
array (size=14)
0 => int 1
1 => int 4
2 => int 5
3 => int 10
4 => int 11
5 => int 12
6 => int 13
7 => int 45
8 => int 56
9 => int 87
10 => int 123
11 => int 332
12 => int 1312
13 => int 4414
标签:fun each code else ret for count gre cti
原文地址:https://www.cnblogs.com/Json159/p/12590871.html