Php judges the code of an empty array program. Many of my friends asked me how to judge the php empty array. I will summarize some common code used to judge the empty array program. if you need to know it, please refer to it. Empty function, this is to judge many friends asked how to judge the php empty array, next I will give you a summary of some common null array judgment program code, a friend who needs to know can go to the reference.
Empty function, which determines that the array value is null
| The code is as follows: |
|
$ Arr = array (""); $ Result = empty ($ arr ); // $ Result = false $ Arr = array (); $ Result = empty ($ arr ); // $ Result = true |
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:
| The code is as follows: |
|
$ Arr = array (), array (), array ()); $ Str = implode (',', $ arr ); If (empty ($ str) echo "null "; Else echo "not empty "; |
Array_filter function
| The code is as follows: |
|
$ Str1_array = array ('one-click tutorial net', '', 'http: // www. bKjia. c0m','', '123 ',''); $ Str1_array = array_filter ($ str1_array ); Print_r ($ str1_array ); ?>
Result Array ( [0] => yijucheng Http://www.bKjia. c0m [4] = & gt; 1654 ) |
Count, size () function
These two functions are the method code used to judge an empty array.
$ Arr = array ("");
Echo count ($ arr );
Echo size ($ arr );
// Output 1
Bytes. Empty function. this is judgment...