如何检查数组是否为空-true或false

问题描述:

我有一个问题,如果我确定数组为空,但isset()传递了它,该如何为返回truefalse的函数设置条件.

I have a question, how do I put a condition for a function that returns true or false, if I am sure that the array is empty, but isset() passed it.

$arr = array();

if (isset($arr)) {
    return true;
} else {
    return false;
}

以这种形式返回bool(true),而var_dump显示array (0) {}.

In this form returns bool(true) and var_dump shows array (0) {}.

如果它是一个数组,则可以只使用if或仅使用逻辑表达式.空数组的值为FALSE,任何其他数组的值为TRUE(演示):

If it's an array, you can just use if or just the logical expression. An empty array evaluates to FALSE, any other array to TRUE (Demo):

$arr = array();

echo "The array is ", $arr ? 'full' : 'empty', ".\n";

PHP手动很好地列出了错误的内容而不是.