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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?