Reputation: 2718
In PHP I am trying to return TRUE if $counter is greater than 0. Would using a ternary operator work in this case. Here is the original code:
if($counter>0){return TRUE;}else{return FALSE;}
could I condense that down to
return $counter>0?TRUE:FALSE
Thanks
Upvotes: 5
Views: 11405
Reputation: 34603
Yes you could condense that, but you can sometime consider also that:
return is_int($counter) && $counter > 0;
This expression checks if it is greater than zero and in addition if $counter
is integer.
Upvotes: 1
Reputation: 82624
You could condense it to return $counter>0
Because that is a Boolean expression itself.
Upvotes: 19