如何在用于创建表单的数组中正确编写isset-> else?
例如:
$this->form[] = array(
'surname' => (isset($vars['sur_name']) ? $vars['sur_name'] : '')
);
我想提出else -> 'surname' => $current_user->user_lastname
非常感谢
答案 0 :(得分:0)
三元条件充当IF ... ELSE条件
$this->form[] = array(
'surname' => (isset($vars['sur_name']) ? $vars['sur_name'] : $current_user->user_lastname)
);
与
相同if (isset($vars['sur_name']){
$this->form[] = array('surname' => $vars['sur_name']);
}
else {
$this->form[] = array('surname' => $current_user->user_lastname);
}