Last active
May 10, 2016 09:24
-
-
Save itsliamjones/fcf3292e9b31d1c9ff84b9f74f750a8b to your computer and use it in GitHub Desktop.
PHP5 Three way comparison (Spaceship Operator)
This file contains 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 | |
/** | |
* PHP5 Three way comparison | |
* | |
* PHP7 This wouldn't be needed, instead you would do something along the lines of - | |
* if/switch ($left <=> $right) { ... } | |
* | |
* @param integer $left | |
* @param integer $right | |
* | |
* @return integer | |
*/ | |
function threeWayComparison($left, $right) | |
{ | |
if ($left < $right) { | |
return -1; | |
} elseif ($left > $right) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment