2012-04-04 56 views
0

这个问题有点奇怪。为什么显示“不为空”,如果发送的值为空?有什么理由呢?检查变量是否为空 - 验证不正确

Parametersapplication/x-www-form-urlencoded 
lists_owned null 
Source 
lists_owned=null 

<?php 
$lists_owned = $_POST['lists_owned']; 

var_dump($lists_owned); // string(4) "null" 

if(!is_null($_POST['lists_owned'])) { 
    echo "Is not null"; I see this echo 
} 
?> 

感谢

+1

伊格纳西奥是正确的,此外,检查如果'$ _POST [ 'lists_owned']'访问它之前设置:'$ lists_owned = isset($ _ POST [ 'lists_owned' ])? $ _POST ['lists_owned']:null;'之后只使用'$ lists_owned'变量,设置$ lists_owned并且从不使用它是没有用的。 – mamadrood 2012-04-04 02:31:32

回答

4

"null"null。如果你想检查"null"那么你应该使用平等。

if($_POST['lists_owned'] != 'null') { 
1

这是因为你的岗位价值是一个名为“空”而不是实际的空值的字符串。

0

看起来你的值实际上是字符串“null”,而不是值null。即

<?php 
$x = "null"; 
$y = null; 
var_dump($x); 
var_dump($y); 
?> 

输出

string(4) "null" 
NULL