dongze8698 2016-08-09 16:45
浏览 23

仅按数组中的数字列排序

Hey im having issues with sorting an array, i chose to use a 2d array a long time ago and im trying to update my site however when i turn the 2d array into a 3d array and try to use array_multisort my values change.

i was using :

array_push($array, $doc[_id], $Fitness);
//but now want to use this
array_push($array, $doc[_id], $Fitness,$title);

The problem with including the title is that it seems to skew the results later when i sort the array:

array_multisort($array); //sort the results to get highest

Is there anyway i can sort the entire array and its contents just by the order of fitness $fitness?

I tried :

array_multisort($results,$Fitness); //sort the results to get highest

but had no luck, do i really have to extract all the values like this? As it seems somewhat overly complicated as a solution...:

foreach ($array as $key => $row) {
    $Fitness[$key] = $row['Fitness'];
}
//and then
array_multisort( $Fitness, SORT_ASC, $array);

Any help would be appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题