我正在寻找一些速记 if/else 代码,但不像$var ? $a : $b
它不需要类似“else”的返回值。我想要的基本上是这样,但更短:
$myVariable = "abc";
echo $myVariable ? $myVariable : "hello";
echo $myVariable ? "hello" : $myVariable;
我有点习惯在 Lua 中做这样的事情,就像:
local myVariable = "abc"
-- In case myVariable is false, print "hello". Otherwise it prints "abc"
print ( myVariable or "hello" )
-- In case myVariable does have something (So, true) print "goodday."
print ( myVariable and "goodday" )
所以我想知道,PHP 是否具有执行此类操作的功能?谢谢。