-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathdata_types.php
More file actions
53 lines (46 loc) · 946 Bytes
/
data_types.php
File metadata and controls
53 lines (46 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
function convert_to_int($input) {
if (settype($input, "int")) {
return $input;
} else {
return 0;
}
}
function convert_to_float($input) {
if (settype($input, "float")) {
return $input;
} else {
return 0.0;
}
}
function convert_to_string($input) {
if (is_array($input)) {
return implode(", ", $input);
} elseif (!settype($input, "string")) { //do falsy check
return "";
} else { //return string value
return $input;
}
}
function convert_to_bool($input) {
if (settype($input, "bool")) {
return $input;
} else {
return false;
}
}
function convert_to_array($input) {
if (settype($input, "array")) {
return $input;
} else {
return array();
}
}
function convert_to_null($input) {
if (!$input || $input === 'null') {
return null;
} else {
return $input;
}
}
?>