4 ms·
This would be a perfect case for a match expression, which, surprisingly, PHP now supports: return match(true) { $a == null && $b == null => null, $a
by 9dev 4y ago
This would be a perfect case for a match expression, which, surprisingly, PHP now supports:
return match(true) {
$a == null && $b == null => null,
$a < $b => -1,
$a > $b => 1,
$a == $b => 0,
default => null;
}
I’m surprised this feature isn’t prevalent in modern languages. It makes the code so concise and easy to understand, it’s marvellous.