dongliang7545 2013-09-27 12:01
浏览 67
已采纳

如何在php中对多维数组进行排序

I have a multidimensional array in php and I want to sort it according to the entered time, but I can't so please give some ideas.

Array
(
    [0] => Array
        (
            [account_id] => 9
            [entered] => 1369374812
        )

    [1] => Array
        (
            [account_id] => 9
            [entered] => 1377587453
        )

    [2] => Array
        (
            [account_id] => 9
            [entered] => 1373542381
        )

    [3] => Array
        (
            [account_id] => 9
            [entered] => 1372988725
        )

    [4] => Array
        (
            [account_id] => 353
            [entered] => 1380191316
        )

    [5] => Array
        (
            [account_id] => 9
            [entered] => 1377587610
        )
)
  • 写回答

3条回答 默认 最新

  • douzhunlan5930 2013-09-27 12:03
    关注

    Try this,

    function aasort (&$array, $key) {
        $sorter=array();
        $ret=array();
        reset($array);
        foreach ($array as $ii => $va) {
            $sorter[$ii]=$va[$key];
        }
        asort($sorter);
        foreach ($sorter as $ii => $va) {
            $ret[$ii]=$array[$ii];
        }
        $array=$ret;
    }
    
    aasort($your_array,"account_id");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于螺旋焊缝的图像处理
  • ¥15 qt 散点图自定义图形
  • ¥100 将USDZ文件转化为带颜色的OBJ文件
  • ¥15 对象代号: , 表单: 不存在!
  • ¥15 WebSocket的问题
  • ¥15 centos上启动kylin后网页报错404
  • ¥20 使用hackrf进行信号收发时接收到的信号幅度太小
  • ¥15 WebSocket的问题
  • ¥15 BDSBAS-B1C和B1C信号有什么不同
  • ¥15 在半圆平面内随机生成点坐标