Created
November 12, 2014 09:49
-
-
Save srph/d23f44812634876c35b0 to your computer and use it in GitHub Desktop.
usort php
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
| function sort($a, $b) { | |
| // If a's contributions is equal to b's contributions, | |
| // return 0, indicating "as it is" | |
| if ( $a->contributions == $b->contributions ) { | |
| return 0; | |
| } | |
| // If a is less than b, put it before b. Otherwise, the opposite | |
| return $a->contributions < $b->contributions ? -1 : 1; | |
| } | |
| usort($response, 'sort'); | |
| foreach($response as $data) { | |
| // Echo each contribution | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment