检查数组为空 [英] Check if array is empty
本文介绍了检查数组为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下code表示记录在 $行
从MySQL查询数组的数组。我还添加了一个如果
语句来检查,如果 $行
变成了空,但它不工作。
The following code shows an array of records in the $rows
array from the MySQL query. I have added also an if
statement to check if $rows
turns up empty, but it is not working.
$rows = array();
$result1 = mysql_query("SELECT * FROM TestPhase where Pid<10", $db) or die("cannot select");
while($row = mysql_fetch_array($result1)) {
$rows []= array(
'id' => $row['id'],
'parent' => $row['parent'],
'name' => $row['name'],
);
}
if($rows == ""){
echo "No Data";
}
本如果
语句不工作。如何检查,如果数组返回空和回声无数据。
This if
statement is not working. How do I check if the array returns empty and echo "No Data".
我将如何检查是否数组在JavaScript空的?我已经放在 $行
阵列中的 VAR treeData code>。
How would I check to see if the array is empty in javascript? I have placed the $rows
array in a var treeData
.
if (treeData) is empty{
$("button").hide();
}
我如何检查是否 treeData code>是空的隐藏按钮。
推荐答案
PHP 结果
只需使用 空()
,即
if(empty($rows)){
echo 'No Data';
}
另外,您还可以使用 计数()
一>,即
if(count($rows) < 1){ // or if(count($rows) === 0)
echo 'No Data';
}
的JavaScript 结果
您可以使用长度
属性
if(treeData.length == 0){
$("button").hide();
}
这篇关于检查数组为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文