App\Libraries\Str::toBoolean PHP Метод

toBoolean() публичный статический Метод

Converts the input string to it's boolean representation.
public static toBoolean ( $str ) : boolean
$str
Результат boolean
    public static function toBoolean($str)
    {
        switch (strtolower($str)) {
            case '1':
            case 'true':
            case 'on':
            case 'yes':
            case 'y':
                return true;
            case '0':
            case 'false':
            case 'off':
            case 'no':
            case 'n':
                return false;
        }
    }

Usage Example

 /**
  * Evaluate the input variable and if the string can be converted to either
  * a boolean, float or integer converts it and return that value.
  * Otherwise simply return the inout variable unchanged.
  *
  * @param $value
  * @return bool|float|int|misc
  */
 public static function correctType($value)
 {
     try {
         if (Str::isBoolean($value)) {
             $value = Str::toBoolean($value);
         } elseif (is_float($value)) {
             $value = floatval($value);
         } elseif (is_int($value)) {
             $value = intval($value);
         }
     } catch (Exception $ex) {
     }
     return $value;
 }