PHP empty() 或 isset() 检查 1 个以上的变量


php empty() or isset() checking more than 1 variable

I use

if(!empty($_POST['login'])){
}

为了检查登录名是否文件已填充,当我检查 1 个变量时它可以工作,但在我使用

if(!empty($_POST['login'],$_POST['password'] )){
}

如何检查 2 个变量,我看到 isset() 也只支持 1 个变量

使用逻辑和操作(&&)以及两次调用empty(),如下所示:

if( !empty( $_POST['login']) && !empty( $_POST['password'])) {
    // $_POST['login'] and $_POST['password'] are both not empty
}

尝试使用这个:

function isempty(){ // Function checks if all of the given arguments are empty
    $empty = true;
    $numargs = func_num_args(); // get the number of given Arguments
    $arg_list = func_get_args(); // get the given Arguments
    for ($i = 0; $i < $numargs; $i++) {
        $empty = $empty && empty($arg_list[$i]);                      
    }
    return $empty;
}

你可以这样称呼它:!isempty($_POST['login'], $_POST['password'])

我还没有测试代码,但应该没问题