Home  >  Article  >  php教程  >  php判断数组为空二个实例

php判断数组为空二个实例

WBOY
WBOYOriginal
2016-06-13 10:03:361186browse

下面提供两个数组判断为空的php代码,因为数组是一种复合型的数据类型我们不能像其它字符型数据一样处理,下面看实例。

方法
1.用count(数组)获取记录 空返回0
2.用is_null 函数

 代码如下 复制代码

$a=array('1','2','3');
echo count($a);


if(is_null($a)){
        echo '000';
}else{
        echo "1111";
}
?>

count方法可行
is_null方法不行

实例二


//判断一个数组是否为空

 代码如下 复制代码
/**
array(
); 空
array(
array(
),
array(
),
array(
)
); 空
array(
array(
),
array(
array(
),
array(
1=>1
)
),
array(
)
); 非 空
*/
function is_array_null($value)
{
if (empty($value))
{
return $value;
}
else
{
return is_array($value) ? array_map('array_null', $value) : addslashes($value);
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn