[英]php isset() is not working
At first I posted my code: 首先,我发布了代码:
//if ($filterResults['id']) {
if (isset($filterResults['id'])){
$select = $this->select();
$select->where('id = ?', $filterResults['id']);
$this->fetchAll($select);
}
Now, the problem is if I use if ($filterResults['id']) {
it gives the expected result but if I use if (isset($filterResults['id'])){
it doesn't work. 现在,问题是如果我使用if ($filterResults['id']) {
它会提供预期的结果,但是如果我使用if (isset($filterResults['id'])){
则不起作用。 I don't see any reason behind this. 我看不出这背后的任何原因。
isset()
will return false if the value is NULL. 如果值为NULL,则isset()
将返回false。 If this is a possibility you may wish to use array_key_exists()
instead: 如果可能的话,您可能希望使用array_key_exists()
代替:
if (array_key_exists('id', $filterResults)) {
[...]
}
It works if I use the isset() like this: 如果我像这样使用isset(),它将起作用:
if ( isset($filterResults['id']) && $filterResults['id'] != null ){
$select = $this->select();
$select->where('id = ?', $filterResults['id']);
$this->fetchAll($select);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.