/*
* return array
* para $arrays array
*
* 将$arrays中的对象根据数组的$item元素进行排序,结果数组长度为$n
*/
function bubbleSort($arrays , $item ,$n){
$cnt=count($arrays);
for($i = 0; $i < $cnt - 1; $i++){//循环比较
for($j = $i + 1; $j < $cnt; $j++){
if($arrays[ $j ][$item] > $arrays[ $i ][$item]){//执行交换
$temp = $arrays[ $i ];
$arrays[ $i ] = $arrays[ $j ];
$arrays[ $j ] = $temp;
}
}
}
if($n < $cnt){
$result = array();
for($i = 0; $i < $n; $i++){
$result[$i] = $arrays[$i];
}
return $result;
}
return $arrays;
}然后在控制器中是这样的:$hotActs = $act_model->where("end_date > '" . $current_date . "'")->order('id desc')->select();
$hotActs = activityInfoUpdateForHot($hotActs);
//在这里会获取权重信息weight
$hotActs = insert_sort($hotActs, "weight");
//在这里根据weight进行排序但是我发现这个函数传入的数组是什么样,传出来的就是什么样,根本不进行排序。请问是因为什么原因?是不是像foreach少了"&"一样?
最佳答案