Note that you can also use a closure to assign the result of a switch (using early returns) to a variable:
$otherVar = (static function($value) {
switch ($value) {
case 0:
return 4;
case 1:
return 6;
case 2:
case 3:
return 5;
default:
return null;
}
})($i);
Of course this way to do is obsolete as it is exactly the purpose of the new PHP 8 match function as indicated in _dom93 answer.