Skip to content

Instantly share code, notes, and snippets.

@mertenvg
Created December 14, 2012 19:49
Show Gist options
  • Save mertenvg/4288093 to your computer and use it in GitHub Desktop.
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.
/**
* 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