After Google, we sorted out the following methods:
I. For Loop
The simplest and most direct method is to use a for loop to traverse the array. An array with known dimensions can be judged, but what if it is an unknown multi-dimensional array?
Ii. implode ();
Use implode () to output the array as a string and determine whether the output string is null. It seems to be a good method at the beginning, but unfortunately it keeps up with 1.1. It won't work for arrays above two dimensions. For example:
$ Arr = array (Array (), array (), array ());
$ STR = implode (',', $ ARR );
If (empty ($ Str) echo "null ";
Else echo "not empty ";
Obviously, $ arr is a two-dimensional array containing three empty arrays. It should be empty, but the output is indeed non-empty. Failed.
3. Count ();
$ Arr = array ("","","");
Echo count ($ ARR );
4. in_array ('', $ ARR ));
$ Arr = array ("D", "S ","");
Echo in_array ('', $ ARR );
This can only indicate empty elements in the array, and it cannot be proved that the array is empty. Obviously not.
5. Empty ();
This cpyeh is similar to the previous methods.
$ Arr = array ("","","");
If (empty ($ ARR) echo "null ";
Else echo "not empty ";
The result is not empty.
6. Use strlen (). If there is no content, it seems that the length is 1.
Add print_r ($ ARR) to the preceding example.