diff --git a/data_types.php b/data_types.php new file mode 100644 index 0000000..8cc068b --- /dev/null +++ b/data_types.php @@ -0,0 +1,59 @@ + 0) { + $conval = intval($input); + } else { + $conval = 0; +} + return $conval; +} + +function convert_to_float($input) { + if($input > 0) { + $conval = floatval($input); + } else { + $conval = 0.0; +} + return $conval; + } + +function convert_to_string($input = '') { + if(is_array($input)) { + $conval = implode(", ", $input); + } else if($input) { + $conval = strval($input); + } else { + $conval = ''; +} + return $conval; +} + +function convert_to_bool($input = null) { + if($input) { + $conval = boolval($input); + } else { + $conval = false; +} + return $conval; +} + +function convert_to_array($input = 0) { + if(!is_array($input)) { + $conval = (array) $input; + } else { + + $conval = $input; + } + return $conval; +} + + function convert_to_null($input){ + if(is_null($input)) { + $conval = null; + } else { + $conval = $input; + } + return $conval; + } + ?> diff --git a/src/data_types.php b/src/data_types.php new file mode 100644 index 0000000..76bff4b --- /dev/null +++ b/src/data_types.php @@ -0,0 +1,59 @@ + 0) { + $conval = intval($input); + } else { + $conval = 0; +} + return $conval; +} + +function convert_to_float($input) { + if($input > 0) { + $conval = floatval($input); + } else { + $conval = 0.0; +} + return $conval; + } + +function convert_to_string($input) { + if(is_array($input)) { + $conval = implode(", ", $input); + } else if (!$input){ + $conval = ''; + } else { + $conval = strval($input); +} + return $conval; +} + +function convert_to_bool($input = null) { + if($input) { + $conval = boolval($input); + } else { + $conval = false; +} + return $conval; +} + +function convert_to_array($input) { + if($input === null) { + return []; + } else if(is_array($input)) { + return $input; + } else { + return [$input]; + } +} + + function convert_to_null($input){ + if(!$input || $input === 'null') { + return null; + } else { + return $input; + } + } + + ?>