Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想对一个对象使用三元运算符。
if($msg == 'hello'){ $o->setHello('hello'); else $o->setHello('bye');
我怎么能那样做?
谢谢
$o->setHello($msg == 'hello' ? 'hello' : 'bye');
怎么样?
试试这个:
($msg == 'hello') ? $o->setHello('hello') : $o->setHello('bye');