作者 王晓刚
1 个管道 的构建 通过 耗费 0 秒

代理人模块

@@ -16,8 +16,23 @@ use think\Db; @@ -16,8 +16,23 @@ use think\Db;
16 16
17 class LoadController extends HomeBaseController 17 class LoadController extends HomeBaseController
18 { 18 {
19 - public function demo(){  
20 - $data=[ 19 + public function demo($data){
  20 + $middle = $data[0];//取一个中间值
  21 + $left = [];//存放小于中间值的数据
  22 + $right = [];//存放大于中间值的数据
  23 + for($i=0;$i<count($data);$i++){
  24 + if($middle<$data[$i]){
  25 + $left[] = $data[$i];
  26 + }else{
  27 + $right[] = $data[$i];
  28 + }
  29 + }
  30 + $left = $this->demo($left);
  31 + $right = $this->demo($right);
  32 + return array_merge($left, array($middle), $right);
  33 + }
  34 + public function test(){
  35 + $array=[
21 ['id'=>1,'name'=>'天津西青','distance'=>10,'unit'=>'KM'], 36 ['id'=>1,'name'=>'天津西青','distance'=>10,'unit'=>'KM'],
22 ['id'=>2,'name'=>'天津河西','distance'=>15,'unit'=>'KM'], 37 ['id'=>2,'name'=>'天津河西','distance'=>15,'unit'=>'KM'],
23 ['id'=>3,'name'=>'山东滨州','distance'=>220,'unit'=>'KM'], 38 ['id'=>3,'name'=>'山东滨州','distance'=>220,'unit'=>'KM'],
@@ -30,9 +45,7 @@ class LoadController extends HomeBaseController @@ -30,9 +45,7 @@ class LoadController extends HomeBaseController
30 ['id'=>10,'name'=>'河北邯郸','distance'=>150,'unit'=>'KM'], 45 ['id'=>10,'name'=>'河北邯郸','distance'=>150,'unit'=>'KM'],
31 ['id'=>11,'name'=>'河北石家庄','distance'=>250,'unit'=>'KM'] 46 ['id'=>11,'name'=>'河北石家庄','distance'=>250,'unit'=>'KM']
32 ]; 47 ];
33 - $result = array_column($data,'distance');  
34 - array_multisort($result,SORT_ASC,$data);  
35 - dump($data); 48 + $this->demo($array);
36 } 49 }
37 public function index(){ 50 public function index(){
38 $type = $this->request->param('type'); 51 $type = $this->request->param('type');