static function typecastVariable($variable, string $type) {
        if($variable === null) {
            return null;
        }
        
        switch($type) {
            case 'array':
                $variable = (array) $variable;
            break;
            case 'bool':
                $variable = (bool) $variable;
            break;
            case 'float':
                $variable = (float) $variable;
            break;
            case 'int':
                $variable = (int) $variable;
            break;
            case 'string':
                $variable = (string) $variable;
            break;
            default:
                throw new \InvalidArgumentException('Unsupported type "'.$type.'"');
            break;
        }
        
        return $variable;
    }
static function typecastVariable($variable, string $type) {
        if($variable === null) {
            return null;
        }
        
        switch($type) {
            case 'array':
                $variable = (array) $variable;
            break;
            case 'bool':
                $variable = (bool) $variable;
            break;
            case 'float':
                $variable = (float) $variable;
            break;
            case 'int':
                $variable = (int) $variable;
            break;
            case 'string':
                $variable = (string) $variable;
            break;
            default:
                throw new \InvalidArgumentException('Unsupported type "'.$type.'"');
            break;
        }
        
        return $variable;
    }
static function typecastVariable ( $ variable , string $ type ) { if ( $ variable === null ) { return null ; } switch ( $ type ) { case 'array' : $ variable = ( array ) $ variable ; break ; case 'bool' : $ variable = ( bool ) $ variable ; break ; case 'float' : $ variable = ( float ) $ variable ; break ; case 'int' : $ variable = ( int ) $ variable ; break ; case 'string' : $ variable = ( string ) $ variable ; break ; default : throw new \ InvalidArgumentException ( 'Unsupported type "' . $ type . '"' ) ; break ; } return $ variable ; }
Typecasts the variable to the type, if not null.
@param mixed   &$variable
@param string  $type
@return mixed|null
@throws \InvalidArgumentException
Typecasts the variable to the type if not null .