php-basic "Variable detection"

Source: Internet
Author: User

Detection of variables

Isset ($var/// using isset to check if a variable exists, this PHP comes with a method that is often used later
// Test---Example 1: if (Isset ($a)) {    " variable a exists ";}Else{     " variable A does not exist " ;}

Results of the output

Variable A does not exist   // because A is not defined

Example 2 below:

$b =null// defined as nullif(Isset ($b)) {    " variable B exists "  ;}Else{    " variable B does not exist ";}

Results:

Variable B does not exist   // variable B is determined to                 not exist // Although it is determined if there is a variable in memory, it is                not related to the value of the variable.  However, if you use Isset to test a variable that is set to NULL, FALSE is returned.                 // Then there is the example 2 output variable B does not exist result.  

Example 3:

$c ='// defined as nullif(Isset ($c)) {    " variable C exists  ";}Else{    " variable C does not exist ";}  // Output results
C is an empty string variable, its value is not empty?, in fact, it is empty, but its value is empty, like a person, there is a bank card, but there is no money in the card,
C is an empty string or a 0 variable is present, and it is loaded with something--and value. It's just too few things to pack.
Variable C exists

PS: Use isset to check the variable, if the variable is null will be returned false

php-Base "Variable detection"

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.