A case study of the difference between PHP functions isset and empty

Source: Internet
Author: User
Tags empty functions

A case study of the difference between PHP functions Isset () and Empty ()

1.? PHP error_reporting (e_all);
2 echo ' <B> undefined $var</b><br> ';
3 echo "Isset test:<br>";
4 if (Isset ($var))
5 {
6 echo ' variable $var existence!<br> ';
7}
8
9
echo "Empty test:<br>";
One if (empty ($var)) {
The value of ECHO ' variable $var is null <Br> ';
13}
Or else
15 {
The value of the Echo ' variable $var is not null <Br> ';
17}
18
echo "Variable direct test:<br>";
if ($var) {
Echo ' variable $var exists!<br> ';
22}
% Else {
echo ' variable $var does not exist!<br> ';
25}
26
Echo '----------------------------------<br> ';
echo ' <B> $var = \ ' </b><Br> ';
echo "Isset test:<br>";
$var = ';
if (Isset ($var))
32 {
The echo ' variable $var exist!<br> ';
34}
35
36
Panax notoginseng echo "Empty test:<br>";
if (empty ($var)) {
The value of the $var variable is null <Br> ';
40}
Or else
42 {
The value of the Echo ' variable $var is not null <Br> ';
44}
45
The echo "Variable direct test:<br>";
if ($var) {
The echo ' variable $var exist!<br> ';
49}
Or else {
No echo ' variable $var not exist!<br> ';
52}
Echo '----------------------------------<br> ';
echo ' <B> $var = 0</b><br> ';
Echo ' isset test:<br> ';
$var = 0;
if (Isset ($var))
58 {
$var echo ' variable exists!<br> ';
60}
61
62
The echo "Empty test:<br>";
if (empty ($var)) {
The value of $var ' variable is null <Br> ';
66}
Or else
68 {
The value of $var echo ' variable is not null <Br> ';
70}
71
The "Variable direct test:<br>";
if ($var) {
The "Variable $var exists!<br>";
75}
Or else {
The $var echo ' variable does not exist!<br> ';
78}
Echo '----------------------------------<br> ';
80
Bayi echo ' <B> $var = Null</b><br> ';
The echo ' isset test:<br> ';
$var = null;
if (Isset ($var))
85 {
The echo ' variable $var exist!<br> ';
87}
88
89
The echo "Empty test:<br>";
(Empty ($var)) {
The value of the $var echo ' variable is null <Br> ';
93}
Or else
95 {
The value of ECHO ' variable $var is not null <Br> ';
97}
98
echo "Variable direct test:<br>";
if ($var) {
Echo ' variable $var exists!<br> ';
102}
Or else {
The echo ' variable $var does not exist!<br> ';
105}
"----------------------------------<br>";
107
108
109 echo ' <B> $var = ' php ' </b><Br> ';
The echo ' isset test:<br> ';
$var = "PHP";
112 if (Isset ($var))
113 {
114 echo ' variable $var exists!<br> ';
115}
116
117
118 echo "Empty Test:<br>";
119 if (empty ($var)) {
The value of the Echo ' variable $var is null <Br> ';
121}
122 Else
123 {
124 echo ' variable $var value is not null <Br> ';
125}
126
127 echo "Variable direct test:<br>";
128 if ($var) {
129 echo ' variable $var exists!<br> ';
130}
131 else {
132 echo ' variable $var does not exist!<br> ';
133



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.