tags:

views:

368

answers:

3

Hello,

I wanna make use of the Ternary Operator with an object.

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

How could I do that?

Thanks

+1  A: 

Try this:

($msg == 'hello') ? $o->setHello('hello') : $o->setHello('bye');
Noah Goodrich
+17  A: 
$o->setHello($msg == 'hello' ? 'hello' : 'bye');
1800 INFORMATION
This one is better. Sadly, I'm out of votes today!
strager
+8  A: 

How about?

$o->setHello($msg == 'hello' ? 'hello' : 'bye');
Cade Roux