Introduction to functions for determining null strings in php

Source: Internet
Author: User
In php, there are many methods to judge whether a string is null, such as null, empty, and isset, which can be used to determine whether a variable or string is null, next I will introduce it to you. string; judge whether the string is null; output... there are many methods to judge whether a string is null in php, such as null = null, empty, and isset, which can be used to determine whether a variable or string is null, next I will introduce it to you.

String; judge whether the string is null; output judgment; you can modify it

The instance code is as follows:

If (emptyempty ($ C_char) return false; // whether if ($ C_char = '') return false has been set; // whether it is null

Use = ""

The instance code is as follows:

 

Empty determines whether it is null

The instance code is as follows:

 

On the surface, it is easy to misunderstand that the empty () function is a function used to judge whether the string is null. In fact, it is not, so I suffered a lot of losses.

The empty () function is used to test whether the variable has been configured. if the variable already exists, non-null string, or non-zero, false is returned; otherwise, true is returned. therefore, if the value of the string is 0, true is returned, that is, the internal statement of empty is executed. this is a trap. for example, suppose $ value = 0; then empty ($ value) = false.

To judge whether the string is null, you can judge it as follows: if ($ value = "")...

* Format: bool empty (mixed var)

* Function: check whether a variable is empty.

* Return value:

* Returns TRUE if the variable does not exist.

* If a variable exists and its values are "", 0, "0", NULL, FALSE, array (), var $ var, and objects without any attribute, true is returned.

* If a variable exists and its values are not "", 0, "0", NULL, FALSE, array (), var $ var, or an object without any attribute, FALSE is returned.

Isset () and empty () judgment methods:

The instance code is as follows:

 "; If (isset ($ var) n {echo 'variable $ var exists!
';} Else {echo' variable $ var does not exist!
';} Echo "empty test:
"; If (emptyempty ($ var) {echo 'variable $ var value is empty
';} Else {echo' variable $ var value is not empty
';} Echo "variable direct test:
"; If ($ var) {echo 'variable $ var exists!
';} Else {echo' variable $ var does not exist!
';}}?>


Address:

Reprinted at will, but please attach the article address :-)

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.