how to sort array according to date in PHP?

Questionshow to sort array according to date in PHP?
Web Guru Staff asked 3 years ago
1 Answers
Web Guru Staff answered 3 years ago

If you want to sort array in PHP use usort() function
Example,
function sortArray($x, $y)
{
$dt1 = strtotime($x[‘datetime’]);
$dt2 = strtotime($y[‘datetime’]);
return $dt1 – $dt2;
}
usort($dataArray, ‘sortArray’);