What is the difference between isset() and empty() in PHP

1, empty to
judge whether a variable is empty

null, false, 00, 0, '0','. Both return true.

2. Isset
judges whether a variable is set

0, 00, '0', 』, '', false,'false', and'null' all return true.
Only variables whose value is null return false

3. If judgment formula
0,
00, 0.0 , '0', 』, false, null return false '00', '0.0','null','false', '' return true

isset determines whether the variable already exists (configuration)

unset deletes (releases) the variable

empty judges whether the variable is empty

is_null Determine whether the variable is NULL

is_null, we can think of it as !isset, which is an inverse operation of isset. The following table can clearly illustrate the relationship between them:

Insert picture description here

It is not difficult to see that as long as the variable is "" or 0, or false and null, as long as these values ​​empty will return true, and isset is to determine whether the variable exists, as long as your variable is not null or unassigned, the return result is true , And is_null is exactly the inverse result of isset.

Of course, if you just want to do the following:
echo !isset( GET [′ a ′]); / / If you can't get the value of variable a echoempty (_GET['a']); //If you can't get the value of variable a echo empty(GE T [a]);/ / The result obtained is not to change the amount of a the value E C H O E m P T Y ( _GET [ 'a']); // if the value of variable a is empty

Guess you like

Origin blog.csdn.net/weixin_45557228/article/details/110129740