Created
October 26, 2020 13:53
-
-
Save mahdiyazdani/bd2c4bb24109907a6f0cfd73a5b47b96 to your computer and use it in GitHub Desktop.
Converting a string (e.g. 'yes' or 'no') to a boolean
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 | |
/** | |
* Converts a string (e.g. 'yes' or 'no') to a bool. | |
* | |
* @since 1.0.0 | |
* @param string $input String to convert. | |
* @return bool | |
*/ | |
function prefix_string_to_bool( $input ) { | |
return is_bool( $input ) ? $input : ( 'yes' === $input || 1 === $input || 'true' === $input || 'TRUE' === $input || '1' === $input ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment