php如何判斷數(shù)組不為空
1、使用函數(shù)“empty()”函數(shù)來判斷,將數(shù)組傳入此函數(shù),如果為true,即代表為空;
$arr = []; if (empty($arr)) { //為空 } else { //不為空 }
2、通過“count()”函數(shù)來獲取數(shù)組條數(shù),再根據(jù)條數(shù)判斷是否小于1,如果小于1,即代表為空;
$arr = []; if (count($arr) < 1) { //為空 } else { //不為空 }
推薦教程:《PHP教程》