Created
December 14, 2012 19:49
-
-
Save mertenvg/4288093 to your computer and use it in GitHub Desktop.
Conert to boolean by using normal PHP falsey equivalencies with the addition of string 'false' which PHP usually considers truthy.
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
/** | |
* Conert to boolean by using normal PHP falsey equivalencies with | |
* the addition of string 'false' which PHP usually considers truthy. | |
* | |
* @param mixed $val Value to convert to boolean | |
* @return boolean Boolean equivalent | |
*/ | |
function bool($val) | |
{ | |
if ( | |
$val === '' || | |
$val === 'false' || | |
$val === '0' || | |
$val === 0 || | |
$val === null || | |
$val === array() || | |
$val === 0.0 || | |
$val === false | |
) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment