Created
June 29, 2015 21:46
-
-
Save LittleMikeNZ/c5fedca9911c7cd90916 to your computer and use it in GitHub Desktop.
Sorts a multi-dimension array by datetime. Can be ASC or DESC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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