我有一个插件,其中包含一个数组在var_dump($array)
:上的情况
array(1) { [""]=> NULL }
我如何检查这是真是假?如果设置了阵列,它将获得例如
array(1) { ["test"]=> string(2) "test" }
我试过
if ($array == NULL)
if ($array[""] == NULL)
if ($array[""] == "NULL")
if ($array == "NULL")
"作为数组索引有点可怕。。。
由于作为第一个元素的$array[0]不起作用,您可以尝试这样来判断数组节点是否为空:
$fillCount = 0;
foreach ($arrData as $key => $value)
{
if (!is_null($value)) $fillCount++;
}
if ($fillCount <= 0)
{
// nothing useful in the array
}
else
{
// useful content in the array
}
如果你的意思是检查值是否为null,你可以使用空的:
if(empty($array[""]))
//element is null
else
//element is not null
数组肯定不是null,因为它有一个元素(array(1))
var_dump(is_null($array[""]));