Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Muzammil's avatar

Sort array by date

Hi all, i'm trying to sort an array by date but not getting any clue , can anyone help me with this?

example array :

 [
      "id": "276",
      "no": "1602-033",
      "customer_name": "Cust_1 ",
      "date": "04-02-2016"
    ],
    [
       "id": "278",
      "no": "1602-038",
      "customer_name": "Cust_5 ",
      "date": "03-02-2016"
    ],
    [
       "id": "281",
      "no": "1602-039",
      "customer_name": "Cust_2 ",
      "date": "04-02-2016"
    ]

Any help or suggestion would be much appreciated!!

0 likes
2 replies
bobbybouwmann's avatar

Well how do you retrieve this information? From a database? In that case you can sort it on the query. If you are not you can convert it to a collection in Laravel and sort it then ;)

bestmomo's avatar

Or just use usort :

function compare($a, $b)
{
    return strtotime($a['date']) - strtotime($b['date']);
}
usort($my_array, 'compare');
2 likes

Please or to participate in this conversation.