如何对多维PHP数组进行排序(最近基于新闻时间的实现)

时间:2016-04-19 11:47:00

标签: php json xml rss

我得到了一些xml格式的最新消息,并改为json格式,Android应用程序需要显示最新消息。我有一个以下的JSON数组...

{
    "rss_news": [
        {
            "title": " ",
            "rss_original_src": "recent_news1(google news)",
            "rss_original_src_img": "",
            "link": "",
            "pubDate": "Tue, 19 Apr 2016 14:05:47 +0530",
            "description": ""
        },
 {
            "title": " ",
            "rss_original_src": "recent_news2(yahoo news)",
            "rss_original_src_img": "",
            "link": "",
            "pubDate": "Tue, 19 Apr 2016 16:05:47 +0530",
            "description": ""
        },
 {
            "title": " ",
            "rss_original_src": "recent_news3",
            "rss_original_src_img": "",
            "link": "",
            "pubDate": "Tue, 19 Apr 2016 11:05:47 +0530",
            "description": ""
        },
....
]
}

现在我需要...基于值(pubDate)的PHP多维数组排序..

提前致谢..

1 个答案:

答案 0 :(得分:0)

首先使用usort($array, 'sortByDate'); function sortByDate($a, $b) { $date1=$a['pubDate']; $date2=$b['pubDate']; //return value based on above two dates. } 将您的JSON字符串转换为PHP数组。

使用usort对数组进行排序,如。

{{1}}