In actual php applications, the isset () function is generally used for judgment. for example: if (isset ($ _ GET [#39; name #39;]) judge whether the passed value is null .... In actual php applications, the isset () function is generally used for judgment. The example is as follows:
If (isset ($ _ GET ['name']) // checks whether the passed value is null. {Echo "the value is null ";}
Instructions for use:
1. the values of Null, 0, and false are all set to TRUE by isset.
2. NULL will be judged as FALSE by isset.
3. isset () is also applicable to the check of array elements and object elements. If an array or object instance is not defined, false is returned for the check of array elements/object elements.
Empty function: checks whether the variable is "null"
For example, the code is as follows:
$ SQL = "select * form abc" $ result = mysql_query ($ SQL); $ row = mysql_fetch_array ($ result); if (emptyempty ($ row )) // start to judge whether it is null. {echo "null";} else {echo "not null ";}
Method 2: The code is as follows:
$ SQL = "select * form abc" $ result = mysql_query ($ SQL); $ row = mysql_fetch_array ($ result); if (! $ Row) // start to judge whether it is null. {echo "null";} else {echo "not null ";}
In fact, when the mysql_fetch_array function is used, if the table is an empty table, false is returned. $ row is not assigned at this time.
Note:Variables with a value of 0 or false or an empty string "" or null, an empty array, will all be judged as null.
Note:A significant difference from empty is that when the variable is not initialized, var = null will report an error.
The PHP instance code is as follows:
$ A = 0; $ B = array (); if ($ a = null) echo '$ a is blank '. ""; if ($ B = null) echo '$ B is blank '. ""; if ($ c = null) echo '$ B is blank '. ""; // The displayed result is // $ a is blank // $ B is blank // Undefined variable: c
4. is_null function: checks whether the variable is "null"
Note: when the variable is assigned "null", the detection result is true.
Note 1: null is case insensitive: $ a = null; $ a = NULL no difference
Note 2: The check result is true only when the variable value is "null". the values 0, null string, false, and empty array are both false.
Note 3: The program reports an error when the variable is not initialized.
The PHP instance code is as follows:
$ A = null; $ B = false; if (is_null ($ a) echo '$ a is Null '. ""; if (is_null ($ B) echo '$ B is Null '. ""; if (is_null ($ c) echo '$ c is Null '. ""; // The displayed result is // $ a is NULL // Undefined variable: c
Article address:
Reprint at will ^ please include the address of this article!