仅检查if条件,而不检查php中terinary运算符中的else条件

仅检查if条件,而不检查php中terinary运算符中的else条件,php,Php,postData包含从前端控制器传递的参数 如果$postData['posp1']有值,则应将其分配给db,否则应分配NULL 仅检查if条件,而不检查else条件,因此在db中添加0,而不是将NULL添加到相应的列中,因为您只检查变量或键是否存在。isset()函数仅检查可用性 使用empty()而不是isset() $insertArray=数组( 'pos1'=>(!empty($postData['pos1'])?$postData['pos1']:NULL), 'pos2'=>(!

postData包含从前端控制器传递的参数

如果$postData['posp1']有值,则应将其分配给db,否则应分配NULL


仅检查if条件,而不检查else条件,因此在db

中添加0,而不是将NULL添加到相应的列中,因为您只检查变量或键是否存在。
isset()
函数仅检查可用性

使用
empty()
而不是
isset()

$insertArray=数组(
'pos1'=>(!empty($postData['pos1'])?$postData['pos1']:NULL),
'pos2'=>(!empty($postData['pos2'])?$postData['pos2']:NULL),
'pos3'=>(!empty($postData['pos3'])?$postData['pos3']:NULL),
'posp'=>(!empty($postData['posp'])?$postData['posp']:NULL),
“状态”=>活动
);

这里的问题是什么?让我们通过将null改为任何其他字符(例如100)来测试它,这是为了测试数据库列配置。列值默认为null而不是null,我将其他数字改为10'pos1'=>(isset($postData['pos1'])?$postData['pos1']:10),仍然没有输入else条件仅当$postData['pos1']为非零时才赋值吗?
$insertArray = array(
            'pos1' => (isset($postData['pos1']) ? $postData['pos1'] : NULL),
            'pos2' => (isset($postData['pos2']) ? $postData['pos2'] : NULL),
            'pos3' => (isset($postData['pos3']) ? $postData['pos3'] : NULL),
            'posp' => (isset($postData['posp']) ? $postData['posp'] : NULL),
            'status' => ACTIVE
            );