2 回答

TA貢獻1909條經(jīng)驗 獲得超7個贊
您需要按如下方式將括號中的每個下一個表達式分組。您忘記將第二個三元表達式括在括號中。
$messageMiddle = ($order->status === "prepairing") ? " your order is being prepared. Make your way towards the store." : (($order->status === "complete") ? ' your order is done! Please show your order-code at the store.' : ' thank you for ordering ');
但無論如何你都應(yīng)該避免這種方法。

TA貢獻1828條經(jīng)驗 獲得超3個贊
對訂單狀態(tài)做出反應(yīng)的更好方法是使用switch 語句。像這樣:
switch ($order->status) {
case "preparing" : $messageMiddle = " your order is being prepared. Make your way towards the store.";
break;
case "complete" : $messageMiddle = " your order is done! Please show your order-code at the store.";
break;
default : $messageMiddle = " thank you for ordering ";
break;
}
很容易看出如何擴展它以對其他狀態(tài)詞做出反應(yīng)。
請注意,我將“準備”更改為“準備”。
程序員追求的目標之一是簡潔的代碼。然而,較短的代碼并不總是更好的代碼。它可能可讀性較差,并且更難以維護和擴展。
- 2 回答
- 0 關(guān)注
- 200 瀏覽
添加回答
舉報