Empty, is_null, and isset in php _ PHP Tutorial

Source: Internet
Author: User
Tags exit in
Empty, is_null, and isset in php. PHP has many function-like functions, but there are slight differences. just like all the is_null, empty, and isset functions analyzed in this article, it does not take much effort, it is really difficult to really engage in PHP with a lot of function-like functions, but there are slight differences, just as all the three functions of is_null, empty, and isset analyzed in this article do not bother, it's really hard to really understand! Let's take a look at the differences between the three functions with the webmaster!

Let's take a look at the functional descriptions of the three functions.

Isset determines whether a variable already exists. if the variable exists, TRUE is returned; otherwise, FALSE is returned.

Empty determines whether the variable is null. if the variable is not null or a non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if the variable is null, TRUE is returned.

Is_null determines whether the variable is NULL

This is the general explanation, but it is confusing. let's take a look at the specific examples!

From this, we can find that if the variable is "" or 0, or false or null, empty returns true as long as these values are empty.

Isset only determines whether a variable exists. as long as the variable is not null or not assigned a value, the returned result is true. If you use isset () to test a variable that is set to NULL, FALSE is returned. Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP.

Is_null is exactly the opposite result of isset. we can regard it! Isset is an inverse operation of isset.

From the above examples, we can draw the following conclusions (which will be frequently used in programming in the future ):

Assume that $ var is of any type.

When empty ($ var) is true, (bool) ($ var) is false. And vice versa.

When is_null ($ var) is true, isset ($ var) is false. And vice versa.

For example:

$ I = $ j + 1;

Here is_null ($ j) is true (it can be understood that because isset ($ j) is false, because $ j is not declared in advance)

Note the following two points:

(1) empty () only detects variables and any non-variables will cause parsing errors. In other words, the following statement does not work: empty (addslashes ($ name )).

(2) isset () can only be used for variables, because passing any other parameter will cause a parsing error. To check whether a constant has been set, use the defined () function.

Articles you may be interested in
  • Use break, continue, goto, return, and exit in multiple loops in PHP
  • Differences in the usage of tinyint, smallint, int, and bigint types in mysql
  • Differences between echo, print, print_r, var_export, and var_dump in php
  • Difference between execute and query methods in ThinkPHP
  • Readonly, disabled, display, and visible
  • Differences among scrollHeight, scrollWidth, scrollLeft, and scrolltop in javascript
  • PHP merges arrays + and array_merge
  • Usage of several keywords such as $ this, static, final, const, and self in php

Is_null, empty, and isset functions are difficult to implement...

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.