Skip to content

Instantly share code, notes, and snippets.

@mahdiyazdani
Created October 26, 2020 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahdiyazdani/bd2c4bb24109907a6f0cfd73a5b47b96 to your computer and use it in GitHub Desktop.
Save mahdiyazdani/bd2c4bb24109907a6f0cfd73a5b47b96 to your computer and use it in GitHub Desktop.
Converting a string (e.g. 'yes' or 'no') to a boolean
<?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