Details about combined comparison operator (<=>) and null coalescing operator (??)
The combined comparison operator return -1, 0, or 1, depending on which is greater than the other:
if ($x <=> $y == -1) { echo '$x < $y'; } elseif ($x <=> $y == 1) { echo '$x > $y'; } else { echo '$x == $y'; }
The null coalescing operator is similar to doing $x ?: $y, but is checking for null instead of false-y:
$x ?: $y
null
$x = null; $y = 'hello'; echo $x ?? $y; //hello echo $x ?: $y; //hello $x = 0; $y = 1; echo $x ?? $y; //0; echo $x ?: $y; //1
The combined comparison operator return -1, 0, or 1, depending on which is greater than the other:
The null coalescing operator is similar to doing
$x ?: $y
, but is checking fornull
instead of false-y: