0

I'm having some problems trying to sort my array on a time. The array has a value with minutes, the lowest has to show at the top.

This is my array:

$voertuigen[] = array(
'img' => $img,
'nummer' => $nummer,
'soort' => $rnaam,
'aankomst' => $formatted
);

I've tryed to use sort()

sort($voertuigen, SORT_NUMERIC);

But then I get this: 9:42 10:50 9:42 13:43 It isn't correctly sorted.

Thanks for helping!

It isn't a datetime, it is just something like this: 10:30 - Minutes:seconds

Jesper
  • 1
  • 1

1 Answers1

0

You can just use usort to define your own comparison and then use DateTime to parse the times in the array and then compare them:

usort($voertuigen, function ($a, $b) {
    return new DateTime($a['aankomst']) > new DateTime($b['aankomst']);
});

Hope this helps!

Rwd
  • 34,180
  • 6
  • 64
  • 78