我正在尝试使用三元运算符缩短我的代码。
这是我的原始代码:
if ($type = "recent") {
$OrderType = "sid DESC";
} elseif ($type = "pop") {
$OrderType = "counter DESC";
} else {
$OrderType = "RAND()";
}
如何在我的代码中使用三元运算符而不是if
s/ else
s?
$OrderType = ($type = "recent") ? "sid DESC" : "counter DESC" ;
这是我尝试过的代码,但不知道如何向其中添加“<code>elseif 部分”。