我有以下陣列PHP沒有檢測到空的POST變量
Array ([productid] => 3
[newid] => 3
[name] =>
[description] =>
[price] =>
[onlinestock] =>
[weight] =>
[keywords] =>
[longdescription] =>
[graphic1] => 89.jpeg
[graphic2] =>
[parameter1] =>
[parameter2] =>
[category1id] => 101
[category2id] =>
[category3id] =>
[category4id] =>
[category5id] =>
[extra1] =>
[extra2] =>
[extra3] =>
[group1id] => 1575
[groupprice1] => 0
[group2id] => 1576
[groupprice2] => 0
[group3id] => 1577
[groupprice3] => 0
[group4id] => 1578
[groupprice4] => 0
[group5id] => 1579
[groupprice5] => 0
我做以下檢查空值
if (empty($_REQUEST["category1id"])){
$_REQUEST["category1id"] = 0;
}else if (empty($_REQUEST["category2id"])){
$_REQUEST["category2id"] = 0;
}else if (empty($_REQUEST["category3id"])){
$_REQUEST["category3id"] = 0;
}else if (empty($_REQUEST["category4id"])){
$_REQUEST["category4id"] = 0;
}else if (empty($_REQUEST["category5id"])){
$_REQUEST["category5id"] = 0;
}else if (empty($_REQUEST["price"])){
$_REQUEST["price"] = 0;
}else if (empty($_REQUEST["onlinestock"])){
$_REQUEST["onlinestock"] = 0;
}else if (empty($_REQUEST["weight"])){
$_REQUEST["weight"] = 0;
}
但不知何故,它沒有檢測到任何這些值作爲空?我不知道這可能是什麼我試過$ _REQUEST ['category1id'] ==「」,這也不起作用。任何幫助,將上述
如果你只是在尋找POST變量使用`$ _POST`,不`$ _REQUEST`。 – BoltClock 2011-01-27 13:59:57
查看:http://php.net/manual/en/function.empty.php。以下內容被認爲是空的: *「」(空字符串) * 0(0作爲整數) *「0」(0作爲字符串) * NULL * FALSE * array()(空數組) * var $ var; (一個變量聲明,但沒有在類中的值) – 2011-01-27 14:01:38