Eiolon Posted August 31, 2011 Share Posted August 31, 2011 Just a silly question. I've been using 1 and 0 to tell if something is true or false, such as if a feature is enabled or not. I see that some use the words true and false. Is there a proper way or is either way correct? Thanks! Link to comment https://forums.phpfreaks.com/topic/246127-true-and-false-or-1-and-0/ Share on other sites More sharing options...
AyKay47 Posted August 31, 2011 Share Posted August 31, 2011 really depends on what it is that you are trying to receive a true false response on.. if it is a boolean function.. then it will return TRUE or FALSE upon execution.. if it is a custom function, or something along those lines.. a 0 or 1 is viable.. Link to comment https://forums.phpfreaks.com/topic/246127-true-and-false-or-1-and-0/#findComment-1264003 Share on other sites More sharing options...
Pikachu2000 Posted August 31, 2011 Share Posted August 31, 2011 An integer 0 (zero) or a boolean FALSE will evaluate to FALSE using both strict === and loose == comparisons. An integer 1 (one) will only evaluate to TRUE with a loose == comparison. Run the code below . . . $vars = array('zero' => 0, 'one' => 1, 'true' => TRUE, 'false' => FALSE); foreach( $vars as $k => $v ) { echo "<br>Key: $k <=> var_dump: "; var_dump($v); echo '<br>'; echo "Loose == comparison to TRUE: "; echo $v == TRUE ? 'Yes<br>' : 'No<br>'; echo "Strict === comparison to TRUE: "; echo $v === TRUE ? 'Yes<br>' : 'No<br>'; echo "Loose == comparison to FALSE: "; echo $v == FALSE ? 'Yes<br>' : 'No<br>'; echo "Strict === comparison to FALSE: "; echo $v == FALSE ? 'Yes<br>' : 'No<br>'; echo '<hr>'; } Link to comment https://forums.phpfreaks.com/topic/246127-true-and-false-or-1-and-0/#findComment-1264014 Share on other sites More sharing options...
xyph Posted August 31, 2011 Share Posted August 31, 2011 (int) 0 !== FALSE Link to comment https://forums.phpfreaks.com/topic/246127-true-and-false-or-1-and-0/#findComment-1264047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.