/ 自定义冒泡算法,减去数据库多重查询带来的负载
// $data 需要运算的二维数组
// $ziduan 需要排序的二维数组的key,默认为数据库的ID
// $where 字符串,传值参数示例 istj,1
// $where1[0]为分割后的第一个参数为数据内的key,
// $where1[1]为分割后的第二个参数为表达式
// $where1[2]为分割后的第二个参数为参数
function MaxMain($data,$ziduan='id',$where=""){
$score=$data;
$len=count($score);
if(!empty($where)){
$where1=explode(",",$where);
for($j=0;$j<$len-1;$j++){
for($i=0;$i<$len-$j-1;$i++){
if($score[$i][$ziduan]<$score[$i+1][$ziduan] && $score[$i][$where1[0]].$where1[1].$where1[2]){
$max=$score[$i+1];
$score[$i+1]=$score[$i];
$score[$i]=$max;
}
}
}
}else{
for($j=0;$j<$len-1;$j++){
for($i=0;$i<$len-$j-1;$i++){
if($score[$i][$ziduan]<$score[$i+1][$ziduan]){
$max=$score[$i+1];
$score[$i+1]=$score[$i];
$score[$i]=$max;
}
}
}
}
return $score;
}
自定义冒泡算法,减去数据库多重查询带来的负载
最新推荐文章于 2024-05-24 20:52:49 发布