Created
June 25, 2013 23:36
-
-
Save hjc/5863452 to your computer and use it in GitHub Desktop.
A small and simple array to convert any and all truthy/falsey values into a hard true or false, in PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//I don't play this mismatched boolean logic bullshit, its true or | |
// false, never 1 or 0 | |
$bool_replaces = [ | |
'0' => false, | |
"1" => true, | |
false => false, | |
true => true, | |
0 => false, | |
1 => true, | |
null => false, | |
"true" => true, | |
"false" => false | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wait, what about
$value = (boolean) $value
? Wouldn't that do the same thing?