-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathdata_types.php
More file actions
110 lines (85 loc) · 1.88 KB
/
data_types.php
File metadata and controls
110 lines (85 loc) · 1.88 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
//convert_to_int
function convert_to_int($int){
$value = intval($int);
if ($value) {
return $value;
} else {
return 0;
}
}
echo convert_to_int("Hold The DOOR!");
//convert_to_float
function convert_to_float($float){
$convert = floatval($float);
if($convert) {
return $convert;
} else {
return 0.0;
}
}
echo convert_to_float("pop");
//convert_to_string
function convert_to_string($string){
if(is_integer($string) || is_string($string) || is_float($string)){
return strval($string);
} elseif (is_array($string)) {
return implode(", ", $string);
} else {
$empty = '';
return $empty;
}
}
echo convert_to_string(["skate",45,"trap"]);
//convert_to_bool
function convert_to_bool($bool){
if(boolval($bool) == 1) {
return true;
} else {
return false;
}
}
echo convert_to_bool(798);
// //convert_to_array
// function convert_to_array($arr){
// if(is_array($arr)) {
// $test = array_values($arr);
// print_r($test);
// }
// elseif (is_int($arr) || is_string($arr) || is_float($arr) || is_bool($arr)) {
// $convert_arr = array($arr);
// print_r(array_values($convert_arr));
// } else {
// if (!$arr == null) {
// $empty = [];
// print_r($empty);
// } else
// print_r(null);
// var_dump($empty);
// }
// }
// echo convert_to_array(45);
//convert_to_array
function convert_to_array($arr){
if (is_array($arr)) {
return $arr;
} elseif (is_int($arr) || is_string($arr) || is_float($arr)) {
$convert_arr = array($arr);
var_dump($convert_arr);
return array_values($convert_arr);
} else {
$nothing = [];
return $nothing;
}
}
return convert_to_array(null);
//convert_to_null
function convert_to_null($null){
if (!$null || $null === "null") {
return null;
} else {
return $null;
}
}
$test = convert_to_null("null");
var_dump($test);