drgc9632 2014-10-20 22:14
浏览 54
已采纳

按整数值排序多维数组

I have the following array:

Array
(
[Address Line 1] => Array
    (
        [llx] => 18.96
        [lly] => 28.88999999999999
    )

[Address Line 2] => Array
    (
        [llx] => 18.73
        [lly] => 35.66
    )

[City State ZIP Code] => Array
    (
        [llx] => 18.51
        [lly] => 47.16999999999999
    )

[Full Name] => Array
    (
        [llx] => 18.86
        [lly] => 20.15999999999997
    )

 )

and i would like to loop through it and sort it by the lly value: so the final outcome should really be

Array
 (
[Full Name] => Array
    (
        [llx] => 18.86
        [lly] => 20.15999999999997
    )

[Address Line 1] => Array
    (
        [llx] => 18.96
        [lly] => 28.88999999999999
    )

[Address Line 2] => Array
    (
        [llx] => 18.73
        [lly] => 35.66
    )

[City State ZIP Code] => Array
    (
        [llx] => 18.51
        [lly] => 47.16999999999999
    )

  )

Any ideas on accomplishing this? Iv been looking over the sorting functions in php but they seem to be mainly focused on single dimension array and nothing like this unless im missing something

  • 写回答

2条回答 默认 最新

  • donglang5157 2014-10-20 22:28
    关注

    Rudie already has the best answer for your particular case, but here's an alternative using array_multisort

    $llx = array();
    $lly = array();
    foreach ($array as $key => $row) {
        $llx[$key] = $row['llx'];
        $lly[$key] = $row['lly'];
    };
    array_multisort($lly, SORT_ASC, $llx, $array);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)