Three function verification for PHP variable Management

Source: Internet
Author: User

The three functions are:

Function 1: isset ():

Used to determine whether a variable has been declared by PHP. It returns a Boolean value. If the variable has been set, true is returned. If the variable is set, false is returned. If the value of the variable is set to null, false is returned. Isset can also be used to determine the elements and object attributes of an array.

Analysis: There are several unclear descriptions in this section. They start to judge whether the statement has been "declared" and then "set". Verify what it is.

TestCode:

<? PHP $ variable1 = NULL; $ variable2 = ""; $ variable3 = "0"; $ variable4 = false; $ variable5 = "test "; // $ variable6 does not declare echo "variable1 --> ". isset ($ variable1 ). "<br/>"; echo "variable2 --> ". isset ($ variable2 ). "<br/>"; echo "variable3 --> ". isset ($ variable3 ). "<br/>"; echo "variable4 --> ". isset ($ variable4 ). "<br/>"; echo "variable5 --> ". isset ($ variable5 ). "<br/>"; echo "variable6 --> ". isset ($ variable6 ). "<br/>";?>

Test results:

 
Variable1 --> variable2 --> 1variable3 --> 1variable4 --> 1variable5 --> 1variable6 -->

Summary: isset returns false only when the variable value is null or the variable is not declared.

Function 2: unset ():

Unset () can be used to cancel the definition of a variable previously defined, and if no other variable is referencing it, all the memory space used by this variable can be released. If you call isset () to check a variable that has been processed by unset (), false is returned.

Function 3: Empty ():

Empty () can be used to check whether a variable is declared or its value is false.

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.