Array
(
[0] => Array
(
[0] => 14/03/2015 14:04:36
[1] => 146
[2] => 41
[3] => 00
[4] => 7
[5] => 189
)
[1] => Array
(
[0] => 13/03/2015 01:19:36
[1] => 146
[2] => 41
[3] => 0
[4] => 4
[5] => 213
)
[2] => Array
(
[0] => 13/03/2015 17:34:36
[1] => 146
[2] => 41
[3] => 0
[4] => 4
[5] => 323
)
)
... a better data structure to use that would make it easier?Yes, there is and you will find it easier to use. It's the ISO-8601 standard format for date and time.
$parts = preg_split("/[\s:\/]/", $dateTimeString);
$dateTimeString = $parts[2]."-".$parts[1]."-".$parts[0]." ".$parts[3].":".$parts[4].":".$parts[5];
Array
(
[0] => Array
(
[0] => 2015-03-17 00:04:36
[1] => 146
[2] => 41
[3] => 0
[4] => X
[5] => 189
)
[1] => Array
(
[0] => 2015-03-14 00:19:36
[1] => 146
[2] => 41
[3] => 0
[4] => X
[5] => 213
)
[2] => Array
(
[0] => 2015-03-11 00:34:36
[1] => 146
[2] => 41
[3] => 0
[4] => X
[5] => 323
)
[3] => Array
(
[0] => 2015-03-14 17:49:36
[1] => 146
[2] => 78442
[3] => 0
[4] => X
[5] => 95
)
)
I then modified Rgonzo1971 function to sort it. I think it works.usort($arrayOfRecords, 'date_compare');
function date_compare($a, $b)
{
$t1 = strtotime($a['0']);
$t2 = strtotime($b['0']);
return $t1 - $t2;
}
Maybe
Open in new window
Regards