Stringy\Stringy::toBoolean PHP Méthode

toBoolean() public méthode

For example, 'true', '1', 'on' and 'yes' will return true. 'false', '0', 'off', and 'no' will return false. In all instances, case is ignored. For other numeric strings, their sign will determine the return value. In addition, blank strings consisting of only whitespace will return false. For all other strings, the return value is a result of a boolean cast.
public toBoolean ( ) : boolean
Résultat boolean A boolean value for the string
    public function toBoolean()
    {
        $key = $this->toLowerCase()->str;
        $map = array('true' => true, '1' => true, 'on' => true, 'yes' => true, 'false' => false, '0' => false, 'off' => false, 'no' => false);
        if (array_key_exists($key, $map)) {
            return $map[$key];
        } elseif (is_numeric($this->str)) {
            return intval($this->str) > 0;
        }
        return (bool) $this->regexReplace('[[:space:]]', '')->str;
    }