Answers for "spaceship operator"

PHP
2

spaceship operator

Return 0 if values on either side are equal
Return 1 if the value on the left is greater
Return -1 if the value on the right is greater
Posted by: Guest on October-11-2021
0

spaceship operator

function cmp_php5($a, $b) {
    return ($a < $b) ? -1 : (($a >$b) ? 1 : 0);
}

function cmp_php7($a, $b) {
    return $a <=> $b;
}
Posted by: Guest on June-22-2021

Browse Popular Code Answers by Language