Skip to content

Instantly share code, notes, and snippets.

@srph
Created November 12, 2014 09:49
Show Gist options
  • Select an option

  • Save srph/d23f44812634876c35b0 to your computer and use it in GitHub Desktop.

Select an option

Save srph/d23f44812634876c35b0 to your computer and use it in GitHub Desktop.
usort php
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