Last active
August 3, 2020 12:38
-
-
Save pecuchet/9fb8ec5c4280705a0b4bbcfe31397caf to your computer and use it in GitHub Desktop.
Returns TRUE for "1", "true", "on" and "yes"; FALSE for "0", "false", "off", "no", and ""; NULL for all other values
This file contains hidden or 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 | |
if (!function_exists('cast_boolean')) { | |
/** | |
* Cast `'true'`, `'false'` etc. to bool. | |
* @param mixed $value | |
* @return bool | |
*/ | |
function cast_boolean($value): bool | |
{ | |
return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment