使用PHP按日期(年月日)对数组进行排序

时间:2019-05-21 14:22:41

标签: php sorting date

我正在为自己的项目开发一个新页面,发现自己在排序逻辑方面遇到了麻烦。

所以,我得到了这个带有新闻的数组(示例):

Array
(

    [0] => Array
        (
            [title] => Lorem Ipsum 1
            [link] => /example/slug-example-1
            [date] => 30 Apr 2019
            [alternative_title] => Ipsum Lorem 1
        )

    [1] => Array
        (
            [title] => Lorem Ipsum 2
            [link] => /example/slug-example-2
            [date] => 31 Jan 2018
            [alternative_title] => Ipsum Lorem 2
        )

    [2] => Array
        (
            [title] => Lorem Ipsum 3
            [link] => /example/slug-example-3
            [date] => 15 Feb 2019
            [alternative_title] => Ipsum Lorem 3
        )

    [3] => Array
        (
            [title] => Lorem Ipsum 4
            [link] => /example/slug-example-4
            [date] => 31 Jan 2018
            [alternative_title] => Ipsum Lorem 4
        )

    [4] => Array
        (
            [title] => Lorem Ipsum 5
            [link] => /example/slug-example-5
            [date] => 27 Oct 2019
            [alternative_title] => Ipsum Lorem 5
        )

    [5] => Array
        (
            [title] => Lorem Ipsum 6
            [link] => /example/slug-example-6
            [date] => 16 Aug 1996
            [alternative_title] => Ipsum Lorem 6
        )

    [6] => Array
        (
            [title] => Lorem Ipsum 7
            [link] => /example/slug-example-7
            [date] => 12 Aug 2001
            [alternative_title] => Ipsum Lorem 7
        )

)

如何有效地按日期(从最新最旧)进行排序?我应该如何使我的代码了解哪个月份先到

0 个答案:

没有答案