The code is as follows: |
Copy code |
<? Php $ Array1 = array (); Print_r ($ array1 ); If (empty ($ array1 )){ Echo 'for empty () is an empty array (an empty array )'; } Else { Echo 'non-empty array (an noempty array) 'for empty )'; } ?> Display result :###################### Array ( ) For empty (), it is an empty array
|
###############################
The code is as follows: |
Copy code |
<? Php $ Array1 = array (); $ Array1 [] = ''; Print_r ($ array1 ); If (empty ($ 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] => ) Non-empty array (an noempty array) for empty) ############################### |
This is not an empty array because it has an element that is a null character (""). Be sure to distinguish it from a null character ("" (an empty string;
Actually
Empty ($ x) equals! Isset ($ x) |! $ X
! Empty ($ x) equals isset ($ x) & $ x
Empty function syntax
Empty -- check whether a variable is empty
Description
Bool empty (mixed var)
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.