Harsha M V
Harsha M V

Reputation: 54949

Ternary operatory for the stament

if( $a == $b) { return true;} 
else { return false;}

how to write a ternary operater for the following ?

is this the way

if($a == $b)? return true; : return false;

Upvotes: 0

Views: 264

Answers (2)

djna
djna

Reputation: 55907

You could just

return ($a == $b)

But if you really want to use the operator

return ( ($a == $b) ? true : false)

Upvotes: 4

BoltClock
BoltClock

Reputation: 723598

You don't need the ternary operator at all. Just return this and you'll get the correct true or false value.

return $a == $b;

Upvotes: 9

Related Questions