如何检查多个isset($_POST['something'])?

How to check multiple isset($_POST['something'])?

如何查询多个isset($_POST['something'])?使用下面提到的代码功能是在没有设置任何东西的情况下调用的?我做错了什么

我的代码在这里

if(!isset($_POST['username']) || $_POST['email'] || $_POST['password'] || $_POST['confirm_pass'] || $_POST['gender'] || $_POST['country']== "") 

{   $username = $this->input->post('username');
    $email = $this->input->post('email');    
    $password = $this->input->post('password');
    $confirm_password = $this->input->post('confirm_pass');
    $gender = $this->input->post('gender');
    $country = $this->input->post('country');
    $this->signupdata->submit_data($username,$email,$password,$confirm_password,$gender,$country);     
 exit(); }
 $this->load->view('signup_view'); 

isset 接受多个变量

对于你的情况,你可以这样做

if (!isset($_POST['username'], $_POST['email'], $_POST['password'], $_POST['confirm_pass'], $_POST['gender'], $_POST['country']) ) {

}

我还应该提到 isset 仅当所有变量都已设置时 return 为真

http://php.net/manual/en/function.isset.php

From Doc:

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

检查空/未设置字段的更好方法可能是这样的。解决这个问题以获得预期的结果:

<?php   
    $req = array("username", "email", "password", "confirm_pass", "gender", "country");
    foreach($req AS $r) {
        if(empty($_POST[$r])) {
            $error = $r . " is a required field";
        } else {
            $username = $this->input->post('username');
            $email = $this->input->post('email');    
            $password = $this->input->post('password');
            $confirm_password = $this->input->post('confirm_pass');
            $gender = $this->input->post('gender');
            $country = $this->input->post('country');
            $this->signupdata->submit_data($username,$email,$password,$confirm_password,$gender,$country);     
            exit();
            $this->load->view('signup_view');
        }    
    }
?>

empty returns 如果未设置字符串,则为错误或通知。

我个人使用 !isset 功能。