Created
April 24, 2014 10:33
-
-
Save daithi-coombes/11249726 to your computer and use it in GitHub Desktop.
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
| /** | |
| * Sort a multidimensional array by datetime. | |
| * usage: | |
| * usort($array, 'sortByOrder'); | |
| */ | |
| function sortByDate($a, $b) { | |
| $t1 = strtotime($a['date']); | |
| $t2 = strtotime($b['date']); | |
| return $t1 - $t2; | |
| } | |
| /** | |
| * Sample | |
| */ | |
| $array = ( | |
| array( | |
| 'member id' => 2544, | |
| 'table id' => 16, | |
| 'date' => '2014-04-04 11:10:36' | |
| ), | |
| array( | |
| 'member id' => 2544, | |
| 'table id' => 15, | |
| 'date' => '2014-04-04 11:10:36' | |
| ), | |
| array( | |
| 'member id' => 2544, | |
| 'table id' => 17, | |
| 'date' => '2014-04-04 11:21:05' | |
| ) | |
| ); | |
| usort($array, 'sortByDate'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment