PHP - Sort object by date without key

Asked

Viewed 137 times

-1

I am receiving from an API the following object:

{
"30/01/2019": [
    {
        "type": "document",
        "filepath": "url",
        "recipients": [
            "Todos"
        ],
        "category": "Ata",
        "date": "30/01/2019"
    },
    {
        "type": "note",
        "note": "Note Example",
        "date": "30/01/2019"
    }
],
"12/01/2019": [
    {
        "type": "document",
        "filepath": "url",
        "recipients": [
            "Todos"
        ],
        "category": "Outra",
        "date": "12/01/2019"
    }
],
"31/01/2019": [
    {
        "type": "document",
        "filepath": "url",
        "recipients": [
            "604"
        ],
        "category": "Ata",
        "date": "31/01/2019"
    }
],
"15/01/2019": [
    {
        "type": "document",
        "filepath": "url",
        "recipients": [
            "604"
        ],
        "category": "Outra",
        "date": "15/01/2019"
    }
],
"01/02/2019": [
    {
        "type": "bill",
        "filepath":"url",
        "date": "01/02/2019",
        "status": 0
    }
]
}

I need to sort it by date, which is actually the key to the object array.

Does anyone know how I could order this object?

1 answer

0

Try to do it this way:

//In Ascending Order

Collect($array)->sortBy('date');

//Or in descending order

Collect($array)->sortByDesc('date');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.