为什么我在common中添加的排序函数不起作用呢?

浏览:444 发布日期:2015/08/30 分类:求助交流 关键字: common,排序
我在common.php中加了这样一个冒泡函数:/*
 * 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少了"&"一样?
最佳答案
评论( 相关
后面还有条评论,点击查看>>