鍍金池/ 問(wèn)答/PHP/ 如何對(duì)多維數(shù)組進(jìn)行排序

如何對(duì)多維數(shù)組進(jìn)行排序

{
    "data":[
        {
            "id":"486",
            "time":"1517310441",
            "content":"",
            "thumb":[
                {
                    "url":"https://123win.oss-cn-shenzhen.aliyuncs.com//upload/IMG_6598.JPG"
                },
                {
                    "url":"https://123win.oss-cn-shenzhen.aliyuncs.com//upload/IMG_6535.JPG"
                },
                {
                    "url":"https://123win.oss-cn-shenzhen.aliyuncs.com//upload/IMG_6534.JPG"
                }
            ],
            "nickname":"咸魚(yú)",
            "headimgurl":"https://123win.oss-cn-shenzhen.aliyuncs.com//upload/p-7a6ec679.jpg",
            "uid":"10668",
            "like":"2",
            "rew":0,
            "smit":0,
            "type":3
        }
    ],
    "comment":[

    ],
    "rew":[
        {
            "ccl_rew":"最愛(ài)礦石奇景,歷史建筑中溫暖的家,蘊(yùn)含著數(shù)代領(lǐng)袖氣息和智慧結(jié)晶。",
            "id":"481",
            "time":"0"
        },
        {
            "ccl_rew":"測(cè)試評(píng)論",
            "id":"489",
            "time":"0"
        }
    ]
}

像這種數(shù)組格式的,如何用里面的time字段進(jìn)行排序,因?yàn)轫?xiàng)目要做一個(gè)類似通知的集合

回答
編輯回答
風(fēng)畔

data 與 rew 有對(duì)應(yīng)關(guān)系么 沒(méi)有的話直接sql中 order by time

2017年7月12日 04:30
編輯回答
巫婆

冒泡啊,原理都是一樣的https://blog.csdn.net/siukong...

2018年2月17日 10:45
編輯回答
亮瞎她

參考菠菜園這個(gè)方法https://www.zkii.net/tech/php... ,多維數(shù)組,想咋排咋排。示例是個(gè)二維的,你可以自己擴(kuò)展下,原理都一樣

2017年6月20日 10:29
編輯回答
神曲
data = data.sort((a, b) => a.time > b.time ? -1 : 1)
2017年9月10日 16:41
編輯回答
使勁操
function my_array_multisort($data,$sort_order_field,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC){
foreach($data as $val){
$key_arrays[]=$val[$sort_order_field];
}
array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$data);
rturn $data;
}

樓主試試這樣能不能達(dá)到你的需求。

2017年7月21日 01:57