检查一个空数组最好的方法? [英] best way to check a empty array?
本文介绍了检查一个空数组最好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何可以递归查询的数组,像这样的例子空内容:
阵列
(
[product_data] =>排列
(
[0] =>排列
(
[标题] =>
[说明] =>
[价格] =>
) )
[product_data] =>排列
(
[1] =>排列
(
[标题] =>
[说明] =>
[价格] =>
) ))
阵列不是空的,但没有内容。我怎么可以用一个简单的功能检查这个?
感谢!
解决方案
功能is_array_empty($ InputVariable)
{
$结果= TRUE; 如果(is_array($ InputVariable)&&计数($ InputVariable)> 0)
{
的foreach($ InputVariable为$值)
{
$结果= $结果&& is_array_empty($值);
}
}
其他
{
$结果=空($ InputVariable);
} 返回$结果;
}
How can I check an array recursively for empty content like this example:
Array
(
[product_data] => Array
(
[0] => Array
(
[title] =>
[description] =>
[price] =>
)
)
[product_data] => Array
(
[1] => Array
(
[title] =>
[description] =>
[price] =>
)
)
)
The array is not empty but there is no content. How can I check this with a simple function?
Thank!!
解决方案
function is_array_empty($InputVariable)
{
$Result = true;
if (is_array($InputVariable) && count($InputVariable) > 0)
{
foreach ($InputVariable as $Value)
{
$Result = $Result && is_array_empty($Value);
}
}
else
{
$Result = empty($InputVariable);
}
return $Result;
}
这篇关于检查一个空数组最好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文