PHP’s preferred method to determine if an array is empty:count($arr),size($arr); (Recommended learning:PHP video tutorial)
Just use this function count. If the output is 0, then the array is empty. The following is a simple test code.
$arr= array(""); echo count($arr); echo size($arr); //输出1 $arr= array(); echo count($arr); echo size($arr); //输出0
PHP method to determine if an array is empty: empty($arr);
empty() The function is to determine whether the variable is empty. If the variable = empty, it returns TRUE , if it is not empty, return FALSE (not an empty value)
$arr= array(""); $result = empty($arr); //$result = false $arr = array(); $result = empty($arr); //$result = true
Are these two methods sufficient to deal with the problem of judging whether simple arrays and multi-dimensional arrays are empty? Personally, I generally use empty() to judge whether the array is empty. , so that the code looks easier to understand.
The above is the detailed content of How to determine whether an array is empty in php. For more information, please follow other related articles on the PHP Chinese website!