If I get an integer variable (anywhere from 0+) There are a few things I can do to make sure the number is not 0(zero):
-
Option 1:
if($number > 0){ // number is not zero } -
Option 2:
if($number){ // number is not zero } -
Option 3:
if((bool) $number){ // number is not zero } -
Option 4:
if(!!$number){ // number is not zero } - Etcetera….
Which one of the above is considered really the best to do?
Or is there an even better option?
Use the identical comparison operaton, which does not do any type juggling (and is faster).
Note: This is assuming the variable is actually a “integer variable”, and not a string that happens to contain a number.