PHP's preferred method to determine if an array is empty: count($arr),size($arr);
Copy code The code is as follows:
$arr= array("");
echo count($arr);
echo size($arr);
//Output 1
Copy code The code is as follows:
$arr= array();
echo count($arr);
echo size($ arr);
//Output 0
PHP method 2 to determine if the array is empty: empty($arr);
Copy code The code is as follows:
$arr= array("");
$result = empty($arr);
//$result = false
$arr = array();
$result = empty($arr);
//$result = true
These two methods are sufficient for simple arrays and To determine whether a multi-dimensional array is empty, I generally use empty() to determine if the array is not empty, so that the code looks easier to understand.
http://www.bkjia.com/PHPjc/324276.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324276.htmlTechArticlePHP preferred method to determine if an array is empty: count($arr),size($arr); Copy the code as follows : $arr= array(""); echo count($arr); echo size($arr); //Output 1 Copy the code as follows: $arr=...