如果没有,我可以得到输出 3 吗?在 PHP 中为 2,反之亦然,不使用 if,while 或三元运算符


Can i get output 3 if no. is 2 and vice versa in php without using if,while or ternary operators?

如果我的输入是2,输出应该是3。
如果输入为 3,则输出应为 2。

我们不能使用 if 或其他或任何三元运算符。

我们不能使用:if($n == 2) { echo 2; }

尝试:

$output=4;
do {
$output--;
$n--;
}while ($n>=2);
echo $output;

或使用mod缩短一个:

echo (3 % $n) + 2;