Today I want to talk about the usage of the empty function. what is the difference between empty and other functions, and whether the normal value is returned when you use it to operate the array.
Today I want to talk about the usage of the empty function. what is the difference between empty and other functions, and whether the normal value is returned when you use it to operate the array.
-
- $ Array1 = array ();
- Print_r ($ array1 );
- If (emptyempty ($ array1 )){
- Echo 'for empty () is an empty array (an empty array )';
- }
- Else {
- Echo 'non-empty array (an noempty array) 'for empty )';
- }
- ?>
Display result: Array (), which is an empty array for empty ()
-
- $ Array1 = array ();
- $ Array1 [] = '';
- Print_r ($ array1 );
- If (emptyempty ($ array1 )){
- Echo 'for empty () is an empty array (an empty array )';
- }
- Else {
- Echo 'non-empty array (an noempty array) 'for empty )';
- }
- ?>
Display result: Array ([0] =>), which is a non-empty array (an noempty Array) for empty (). This is not an empty array, because it has an element that is null (""), it must be noted that it is different from the null character ("" (an empty string;
Actually:
Empty ($ x) equals! Isset ($ x) |! $ X
! Empty ($ x) equals isset ($ x) & $ x
Empty function syntax:Bool empty (mixed var)
Empty -- check whether a variable is empty.
Description: If var is a non-null or non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if var is null, TRUE is returned.