Jump to content

Confirming false


perikles

Recommended Posts

If you want to check if a variable is really false, and not anything else, you should do this:

 

if ($var === false)

 

If you want to check if a variable is false or null or 0 or empty string, use this:

 

if ($var == false)

 

If you want to set a variable to false:

 

$var = false;

 

So to set and do a strict check:

 

$var = false;
if ($var === false) { print "False is true."; }

Link to comment
https://forums.phpfreaks.com/topic/227010-confirming-false/#findComment-1171226
Share on other sites

Rifts, the problem with that is if the value of $awesomeVar is 0 (zero), it will evaluate to true. To check for boolean FALSE, you need to use the identical comparison === operator, not the equals comparison == operator.

if( $var === FALSE )

Link to comment
https://forums.phpfreaks.com/topic/227010-confirming-false/#findComment-1171231
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.