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
You can condense it to return $counter>0
return $counter>0
Because it is a logical expression itself.
return ($counter > 0) ? TRUE : FALSE;
If you like, yes you can!
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.
$counter