Returns TRUE if counter is greater than 0?

In PHP, I am trying to return TRUE if $ counter is greater than 0. Uses the ternary operator in this case. Here is the source code:

if($counter>0){return TRUE;}else{return FALSE;} 

Is it possible to condense to

 return $counter>0?TRUE:FALSE 

thanks

+4
source share
3 answers

You can condense it to return $counter>0

Because it is a logical expression itself.

+15
source
 return ($counter > 0) ? TRUE : FALSE; 

If you like, yes you can!

+3
source

Yes, you could condense this, but sometimes you might think that:

 return is_int($counter) && $counter > 0; 

This expression checks if it is greater than zero and, moreover, if $counter is an integer.

0
source

All Articles