-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphptest.php
144 lines (126 loc) · 2.62 KB
/
phptest.php
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php // Defining my constants
define('EOL',"<br />\n");
?>
<?php
$sevenDwarves[] = 'happy';
$sevenDwarves[] = 'doc';
$sevenDwarves[] = 'bashful';
$sevenDwarves[] = 'sneezy';
$sevenDwarves[] = 'angry';
$sevenDwarves[] = 'dopey';
$sevenDwarves[] = 'sleepy';
print_r ($sevenDwarves);
$keys = array_keys($sevenDwarves);
$vals = array_values($sevenDwarves);
print_r ($vals).EOL;
foreach ($sevenDwarves as $vals) echo $vals.EOL;
?>
<?php
$color = 'red';
$count = 0;
if($count = 100) {
print $color;
}
?>
<?php
$number2 = 2;
$string2 = "2";
$number98 = 98;
$string98 = "98";
if($number2 = 100) {
if($number98 == $string98) {
if($number2 === $string2) {
print $number2 + $string98;
}
else {
print $number98 . $string98;
}
}
else {
print $number98;
}
}
else {
print $number2;
}
?>
<br />
<?php
function multiply ($num1, $num2=1) {
return $num1*$num2;
};
echo multiply(7);
function test ($str1='Blank',$str2) {
return $str1.$str2;
}
echo "<br />\ntest('String1','String2')<br />\n";
echo test('String1','String2');
echo "<br />\ntest()<br />\n";
echo test();
function addOne ($i=func_get_args) {
foreach ($i as $add) {
$sum = $add++;
}
echo 'The sum is $sum.';
}
?>
<br />
<?php
$tests = array (
1.93E+11,
-1.93E-2,
// 1 1/4,
0xff12ab,
// 1.22.33E+11,
1+1/4
);
foreach($tests as $element){
if(is_numeric($element)) {
echo "'{$element}' is numeric <br />", PHP_EOL;
} else {
echo "'{$element}'is NOT numeric <br />", PHP_EOL;
}
}
?>
<br />
<?php
$globalName = "Zoe";
function sayHello() {
$localName = "Harry";
echo "Hello, $localName!<br />";
}
sayHello();
echo "The value of \$globalName is: '$globalName' <br />";
echo "The value of \$localName is: '$localName' <br />";
?>
<br />
<?php
function createWidget(){
static $numWidgets = 0;
return ++$numWidgets;
}
echo "Creating some widgets...<br />";
echo createWidget() . " created so far.<br />";
echo createWidget() . " created so far.<br />";
echo createWidget() . " created so far.<br />";
?>
<h1>The Main Script</h1>
<?php
include 'file2.php';
include 'file1.php';
print $greeting;
?>
<?php echo "<br />";?>
<?php
var_dump((bool) "0.0"); // bool(false)
var_dump((bool) ''); // bool(true)
var_dump((bool) 0.0); // bool(true)
var_dump((bool) ""); // bool(true)
var_dump((bool) (int)"strings are always true"); // bool(true)
var_dump((bool) 0); // bool(true)
var_dump((bool) NULL); // bool(false)
var_dump((bool) "000a"); // bool(true)
var_dump((bool) $colors=array());
var_dump((bool) "0");
var_dump((bool) "FALSE");
?>