LearningPHP judges that the array is null and the 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?
PHP judges whether the array is null 2 and 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 ());
$ 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.
PHP judges the array as null 3, count ();
$ Arr = array ("","","");
Echo count ($ arr );
PHP judges that the array is null. 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.
PHP determines if the array is null. 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.
PHP judges that the array is null. Use strlen (). If there is no content, it seems that the length is 1.
You can also add print_r ($ arr) in the preceding example.