PHP object and ternary operator

I want to use the ternary operator with an object.

if($msg == 'hello'){
    $o->setHello('hello');
else
    $o->setHello('bye');

How can i do this?

thanks

+3
source share
3 answers

Try the following:

($msg == 'hello') ? $o->setHello('hello') : $o->setHello('bye');
+2
source
$o->setHello($msg == 'hello' ? 'hello' : 'bye');
+23
source

What about?

$o->setHello($msg == 'hello' ? 'hello' : 'bye');
+9
source

All Articles