Created
September 1, 2015 12:05
-
-
Save fullybaked/d1e08a725169a65a748e to your computer and use it in GitHub Desktop.
Usort with PHP7 Spaceship vs PHP5.6
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
<?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