Skip to content

Instantly share code, notes, and snippets.

@fullybaked
Created September 1, 2015 12:05
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fullybaked/d1e08a725169a65a748e to your computer and use it in GitHub Desktop.
Save fullybaked/d1e08a725169a65a748e to your computer and use it in GitHub Desktop.
Usort with PHP7 Spaceship vs PHP5.6
<?php
// PHP 5.6
usort($array, function($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
});
// PHP 7 with spaceship operator
usort($array, function($a, $b) {
return $a <=> $b;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment