Instance study: differential variables of PHP functions isset and empty $ var does not exist instance study of differential variables of PHP functions isset and empty $ var does not exist
Study the differences between the isset () and empty () functions in PHP
1 2 echo'Undefined $ var
';
3 echo 'isset test:
';
4 if (isset ($ var ))
5 {
6 echo 'variable $ var exists!
';
7}
8
9
10 echo 'empty test:
';
11 if (empty ($ var )){
12 echo 'variable $ var value is empty
';
13}
14 else
15 {
16 echo 'variable $ var value is not empty
';
17}
18
19 echo 'variable test:
';
20 if ($ var ){
21 echo 'variable $ var exists!
';
22}
23 else {
24 echo 'variable $ var does not exist!
';
25}
26
27 echo '----------------------------------
';
28 echo'$ Var = \'\'
';
29 echo 'isset test:
';
30 $ var = '';
31 if (isset ($ var ))
32 {
33 echo 'variable $ var exists!
';
34}
35
36
37 echo 'empty test:
';
38 if (empty ($ var )){
39 echo 'variable $ var value is empty
';
40}
41 else
42 {
43 echo 'variable $ var value is not empty
';
44}
45
46 echo 'variable direct test:
';
47 if ($ var ){
48 echo 'variable $ var exists!
';
49}
50 else {
51 echo 'variable $ var does not exist!
';
52}
53 echo '----------------------------------
';
54 echo'$ Var = 0
';
55 echo 'isset test:
';
56 $ var = 0;
57 if (isset ($ var ))
58 {
59 echo 'variable $ var exists!
';
60}
61
62
63 echo 'empty test:
';
64 if (empty ($ var )){
65 echo 'variable $ var value is empty
';
66}
67 else
68 {
69 echo 'variable $ var value is not empty
';
70}
71
72 echo 'variable test:
';
73 if ($ var ){
74 echo 'variable $ var exists!
';
75}
76 else {
77 echo 'variable $ var does not exist!
';
78}
79 echo '----------------------------------
';
80
81 echo'
$ Var = null
';
82 echo 'isset test:
';
83 $ var = null;
84 if (isset ($ var ))
85 {
86 echo 'variable $ var exists!
';
87}
88
89
90 echo 'empty test:
';
91 if (empty ($ var )){
92 echo 'variable $ var value is empty
';
93}
94 else
95 {
96 echo 'variable $ var value is not empty
';
97}
98
99 echo 'variable test:
';
100 if ($ var ){
101 echo 'variable $ var exists!
';
102}
103 else {
104 echo 'variable $ var does not exist!
';
105}
106 echo '----------------------------------
';
107
108
109 echo'
$ Var = 'php'
';
110 echo 'isset test:
';
111 $ var = 'php ';
112 if (isset ($ var ))
113 {
114 echo 'variable $ var exists!
';
115}
116
117
118 echo 'empty test:
';
119 if (empty ($ var )){
120 echo 'variable $ var value is empty
';
121}
122 else
123 {
124 echo 'variable $ var value is not empty
';
125}
126
127 echo 'variable direct test:
';
128 if ($ var ){
129 echo 'variable $ var exists!
';
130}
131 else {
132 echo 'variable $ var does not exist!
';
133