由于一些奇怪的原因,我的PHP没有看到第二个参数的值。PHP函数看不到第二个参数的值
我的代码:
PHP函数:
public function getVacs($key, $id = null, $deleted = null, $deleted_key = null) {
if(!$id) {
$data = $this->_db->getAll('vacatures', $key);
} elseif(!empty($deleted)) {
$data = $this->_db->getAll('vacatures', $key, $id, $deleted, $deleted_key);
} else {
$data = $this->_db->getAll('vacatures', $key, $id);
}
if($data->count()) {
$this->_data = $data->results();
$this->_count = $data->count();
return true;
}
}
调用函数:
} elseif(isset($_POST['all'])) {
$vacs = $v->getVacs('delete', '0');
echo json_encode($v->data());
exit();
}
的问题是,该功能不会看到的$id
值。
它运行第一个if
,它应该运行else
。
Jup,我用下面的工作,'if(!is_null($ id))'。谢谢! – Chris
@Chris yes if(!is_null($ id))'当$ id =='0'就是你想要的时候'会评估为'true'?当'$ id'的值是'null'之外的任何东西时,我以为你不想进入第一个区块? – Ray
我移动了'else'作为第一个'if'。所以现在它将首先检查'$ id'是不是'null' – Chris