Skip to content

Instantly share code, notes, and snippets.

@LittleMikeNZ
Created June 29, 2015 21:46
Show Gist options
  • Save LittleMikeNZ/c5fedca9911c7cd90916 to your computer and use it in GitHub Desktop.
Save LittleMikeNZ/c5fedca9911c7cd90916 to your computer and use it in GitHub Desktop.
Sorts a multi-dimension array by datetime. Can be ASC or DESC.
/*
Usage:
usort($array, array($this, "date_compare"));
To sort DESC use return $t2 - $t1
To sort ASC use return $t1 - $t2
*/
public function date_compare($a, $b)
{
$t1 = strtotime($a['datetime']);
$t2 = strtotime($b['datetime']);
return $t2 - $t1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment