duanhong1985 2013-10-07 07:08
浏览 36

在php [duplicate]中按值排序数组数组

This question already has an answer here:

I have an array named as $result which have contents something like this:

Array (    
        [1114_435] => stdClass Object
        (
            [uid] => 435
            [v_first_name] => fHerter
            [v_last_name] => Herter
            [id] => 1114
            [v_title] => Morning Stretch
            [fk_resident_id] => 435
            [v_location] => Front Lawn
            [i_started_date] => 1357054200
        )

[1114_444] => stdClass Object
    (
        [uid] => 444
        [v_first_name] => fXYZ
        [v_last_name] => XYZ
        [id] => 1114
        [v_title] => Morning Stretch
        [fk_resident_id] => 444
        [v_location] => Front Lawn
        [i_started_date] => 1357054200
    )

[1114_448] => stdClass Object
    (
        [uid] => 448
        [v_first_name] => fDavidson
        [v_last_name] => Davidson
        [id] => 1114
        [v_title] => Dinner
        [fk_resident_id] => 448
        [v_location] => Front Lawn
        [i_started_date] => 1357051000
    )
)

I want to sort it on the basis of i_started_date. I tried using ksort, asort etc but no luck, maybe i wasn`t using it properly. Any help would be highly appreciated.

Thanks!

</div>
  • 写回答

1条回答 默认 最新

  • doubaomao9304 2013-10-07 07:11
    关注

    Try something like this:

    function sortArray($data)
    {
    
        $sortArray = array();
    
        foreach($data as $dt)
        {
            foreach($dt as $key=>$value)
            {
                if(!isset($sortArray[$key]))
                {
                    $sortArray[$key] = array();
                }
    
            $sortArray[$key][] = $value;
            }
        }
    
        $orderby = "1"; //change this to whatever key you want from the array
        array_multisort($sortArray[$orderby],SORT_ASC,$data);
    
    return $data;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP