Answer the question
In order to leave comments, you need to log in
How to sort an array by date?
Good time of day. How to sort an array by date?
$arr= [
[
"header"=>'',
"title"=>'',
"data"=>'12 июнь 2021',
],
[
"header"=>'',
"title"=>'',
"data"=>'30 июнь 2021',
],
[
"header"=>'',
"title"=>'',
"data"=>'1 июля 2021',
],
[
"header"=>'',
"title"=>'',
"data"=>'1 январь 2020',
]
];
Answer the question
In order to leave comments, you need to log in
Use the usort function . For it, you will need to write a comparison callback function that will receive elements from your array.
In this callback function, you will need to translate the date of the form "July 1, 2021" either into a timestamp or into a DateTime object, and already use them in comparison with each other.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question