Many of my friends asked me how to judge the php empty array. next I will summarize some common code used to judge the empty array program. if you need to know about it, please refer to the empty function. this is to judge the array value.
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, which determines that the array value is null
The instance code is as follows:
- $ Arr = array ("");
- $ Result = emptyempty ($ arr );
- // $ Result = false
- $ Arr = array ();
- $ Result = emptyempty ($ 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 instance code is as follows:
- $ Arr = array (), array (), array ());
- $ Str = implode (',', $ arr );
- If (emptyempty ($ str) echo "null ";
- Else echo "not empty ";
Array_filter function
The instance code is as follows:
- $ Str1_array = array ('one-click tutorial net', '', 'http: // www.111cn.net ','', '123 ','');
- $ Str1_array = array_filter ($ str1_array );
- Print_r ($ str1_array );
- ?>
Result
Array ([0] => a Poly tutorial network [2] => http://www.111cn.net [4] => 1654)
Count, size () function
The two functions are the method code for determining the null array:
- $ Arr = array ("");
- Echo count ($ arr );
- Echo size ($ arr );
- // Output 1