So one way to do it would be..
所以一种方法是..
if(isset($arrayVar)) {
if(is_array($arrayVar)) {
if(count($arrayVar) > 0) {
// Success
print_r($arrayVar);
}
}
}
Are there any better ways?
有没有更好的方法?
3 个解决方案
#1
#2
2
if (!empty($arrayVar) && is_array($arrayVar))
!empty
covers both isset
and empty arrays (all falsey values in fact), you then just need to confirm that it's also actually an array.
!empty覆盖了isset和empty数组(实际上都是falsey值),然后你需要确认它实际上也是一个数组。
#3
-1
You can check like this,
你可以这样检查,
if(is_array($arrayVar) && sizeof($arrayVar) > 0)
{
echo 'Array value exists';
}
else
{
echo 'array empty or it is not array';
}
#1
7
You can do it using is_array and empty:
你可以使用is_array和empty来做到这一点:
if (!empty($arrayVar) && is_array($arrayVar)) {
// ...
}
empty()
will check if isset and not empty at once.
empty()将检查是否isset而不是立即为空。
#2
2
if (!empty($arrayVar) && is_array($arrayVar))
!empty
covers both isset
and empty arrays (all falsey values in fact), you then just need to confirm that it's also actually an array.
!empty覆盖了isset和empty数组(实际上都是falsey值),然后你需要确认它实际上也是一个数组。
#3
-1
You can check like this,
你可以这样检查,
if(is_array($arrayVar) && sizeof($arrayVar) > 0)
{
echo 'Array value exists';
}
else
{
echo 'array empty or it is not array';
}