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

代理人模块

... ... @@ -16,8 +16,23 @@ use think\Db;
class LoadController extends HomeBaseController
{
public function demo(){
$data=[
public function demo($data){
$middle = $data[0];//取一个中间值
$left = [];//存放小于中间值的数据
$right = [];//存放大于中间值的数据
for($i=0;$i<count($data);$i++){
if($middle<$data[$i]){
$left[] = $data[$i];
}else{
$right[] = $data[$i];
}
}
$left = $this->demo($left);
$right = $this->demo($right);
return array_merge($left, array($middle), $right);
}
public function test(){
$array=[
['id'=>1,'name'=>'天津西青','distance'=>10,'unit'=>'KM'],
['id'=>2,'name'=>'天津河西','distance'=>15,'unit'=>'KM'],
['id'=>3,'name'=>'山东滨州','distance'=>220,'unit'=>'KM'],
... ... @@ -30,9 +45,7 @@ class LoadController extends HomeBaseController
['id'=>10,'name'=>'河北邯郸','distance'=>150,'unit'=>'KM'],
['id'=>11,'name'=>'河北石家庄','distance'=>250,'unit'=>'KM']
];
$result = array_column($data,'distance');
array_multisort($result,SORT_ASC,$data);
dump($data);
$this->demo($array);
}
public function index(){
$type = $this->request->param('type');
... ...