2012-06-26 26 views
-1

我用PHP空()或isset()函數檢查超過1可變

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

用於檢查登錄的文件被填滿,當我檢查1個變量,但沒有工作,當我用

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

如何檢查2個變量,我看到isset()函數也只支持1個變量

+1

isset將採取多變量 - http://php.net/manual/en/function.isset.php – andrewsi

+0

你的意思是'var_dump(isset($ a,$ b)); // TRUE'? – Wizard

+0

如果$ a和$ b都被設置,'isset($ a,$ b)'將返回true;這是你的意思嗎? – andrewsi

回答

3

使用邏輯與操作(&&)有兩個電話一起empty(),像這樣:

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

嘗試使用此:

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'])

我沒有測試的代碼,但它應該是罰款