private static function castValue($val, $trim = false)
    {
        if (is_array($val)) {
            foreach ($val as $key => $value) {
                $val[$key] = self::castValue($value);
            }
        } elseif (is_string($val)) {
            if ($trim) {
                $val = trim($val);
            }
            $val = stripslashes($val);
            $tmp = strtolower($val);

            if ($tmp === 'false' || $tmp === 'true') {
                $val = $tmp === 'true';
            } elseif (is_numeric($val)) {
                return $val + 0;
            }

            unset($tmp);
        }

        return $val;
    }
private static function castValue($val, $trim = false)
    {
        if (is_array($val)) {
            foreach ($val as $key => $value) {
                $val[$key] = self::castValue($value);
            }
        } elseif (is_string($val)) {
            if ($trim) {
                $val = trim($val);
            }
            $val = stripslashes($val);
            $tmp = strtolower($val);

            if ($tmp === 'false' || $tmp === 'true') {
                $val = $tmp === 'true';
            } elseif (is_numeric($val)) {
                return $val + 0;
            }

            unset($tmp);
        }

        return $val;
    }
private static function castValue ( $ val , $ trim = false ) { if ( is_array ( $ val ) ) { foreach ( $ val as $ key => $ value ) { $ val [ $ key ] = self :: castValue ( $ value ) ; } } elseif ( is_string ( $ val ) ) { if ( $ trim ) { $ val = trim ( $ val ) ; } $ val = stripslashes ( $ val ) ; $ tmp = strtolower ( $ val ) ; if ( $ tmp === 'false' || $ tmp === 'true' ) { $ val = $ tmp === 'true' ; } elseif ( is_numeric ( $ val ) ) { return $ val + 0 ; } unset ( $ tmp ) ; } return $ val ; }
Try determinate the original type variable of a string

@param  string  $val  string containing possibles variables that can be cast to bool or int
@param  boolean $trim indicate if the value passed should be trimmed after to try cast
@return mixed   returns the value converted to original type if was possible
Try determinate the original type variable of a string