Skip to content

Instantly share code, notes, and snippets.

@hjc
Created June 25, 2013 23:36
Show Gist options
  • Save hjc/5863452 to your computer and use it in GitHub Desktop.
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.
<?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
];
@xeoncross
Copy link

Wait, what about $value = (boolean) $value? Wouldn't that do the same thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment