1、isset function: determine whether the variable is initialized or not
Description: It doesn't determine whether a variable is empty or not, it can be used to determine whether an element in an array has been defined or not.
Note: When using isset to determine if an array element is initialized, it is about 4 times more efficient than array_key_exists.

<?php
//$a = '';
//$a = false;
$a['c'] = '';
if (!isset($a)) echo '$a is not initialized' . "<br/>";
if (!isset($b)) echo '$b not initialized' . "<br/>";
if (isset($a['c'])) echo '$a has been initialized' . "<br/>";
//Results
// $b is not initialized
// $a has been initialized
2, empty () function: detect whether the variable is ”empty”
Description: any uninitialized variable, variable with value 0 or false or empty string ”” or null, empty array, object without any attributes, empty(variable) == true.
Note 1: Uninitialized variables can also be detected as ”null” by empty.
Note 2: empty can only detect variables, not statements.
<?php
$a = 0;
$b = '';
$c = array();
if (empty($a)) echo '$a is empty' . "<br/>";
if (empty($b)) echo '$b is empty' . "<br/>";
if (empty($c)) echo '$c is empty' . "<br/>";
if (empty($d)) echo '$d is empty' . "<br/>";
//Results
// $a is null
// $b is empty
// $c is empty
// $d is empty
var_dump(empty(null)); var_dump(empty(0)); var_dump(empty(0))
var_dump(empty(null)); var_dump(empty(0));
var_dump(empty(null)); var_dump(empty(0)); var_dump(empty(''));
var_dump(empty('')); var_dump(empty([]));
// Result
// bool(true)
// bool(true)
// bool(true)
// bool(true)
3, var == null function: to determine whether the variable is ”empty”
Remarks: Variables, empty arrays, and variables whose value is 0 or false or the empty string ”” or null will be judged as null.
Note: The significant difference with empty is that var == null will report an error if the variable is not initialized.
<?php
$a = 0;
$b = array();
if ($a == null) echo '$a is null' . "";
if ($b == null) echo '$b is null' . ""; if ($b == null) echo '$b is empty' .
if ($c == null) echo "$c is null" . "";
// The result is displayed as
// $a is null
// $b is null
// Undefined variable: c
4. is_null function: detect whether the variable is ”null”.”
Remarks: When the variable is assigned to ”null”, the result will be true.
Note 1: null is not case sensitive: a = null; a = null; a = NULL makes no difference.
Note 2: Only when the value of the variable is ”null”, the result will be true, 0, empty string, false, empty array will be false.
Note 3: The program will report an error if the variable is not initialized.
<?php
$a = null;
$b = false;
if (is_null($a)) echo '$a is NULL' . "";
if (is_null($b)) echo '$b is NULL' . ""; echo '$b is NULL' .
if (is_null($c)) echo "$c is NULL" . "";
// The result is displayed as
// $a is NULL.
// Undefined variable: c
5. var === null function: detect whether the variable is ”null”, and the type of the variable must also be ”null”.”
Remarks: When the variable is assigned to ”null” and the type of the variable is also ”null”, the result will be true.
*Note 1: All equal and is_null have the same effect on determining ”null”.
*Note 2: The program will report an error if the variable is not initialized.
Summary:
In PHP, ”NULL” and “empty” are two different concepts.
isset is mainly used to determine whether a variable has been initialized or not.
empty can judge variables with values of “false”, ”empty”, ”0″, ”NULL”, ”uninitialized ” variables are determined to be TRUE.
is_null only judges variables with the value “NULL” as TRUE.
var == null Judges all variables with values of “false”, ”null”, ”0″, ”NULL” as TRUE.
var === null Judges only variables with a value of “NULL” as TRUE.
Note: When determining whether a variable is truly ”NULL”, is_null is used in most cases, thus avoiding the interference of values such as ”false” and ”0″.








![[Black Apple Installation Tutorial] macOS 12 Monterey Original OC Boot - Xiaoqi Notes](https://www.snswm.com/wp-content/uploads/2022/05/image-13.png)





No comments