Reputation: 54949
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
Reputation: 55907
You could just
return ($a == $b)
But if you really want to use the operator
return ( ($a == $b) ? true : false)
Upvotes: 4
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