0

我想更改此代码示例,以便同时评估所有这些条件。如果多个条件为真,则可以将多个参数传递给“注册”函数。

我最初尝试使用 switch,但每个条件都需要能够评估不同的条件。

在这方面为我指明正确方向的任何帮助都会很棒。

    if ($this->form_validation->run() == FALSE) {
        $this->signup();

    } else if ($this->membership_model->check_field('username',$this->input->post('username'))) {

        $this->signup("An account with the username you've entered already exists.");

    } else if ($this->membership_model->check_field('email_address',$this->input->post('email_address'))) {

        $this->signup("An account with the e-mail you've entered already exists.");

    }
4

2 回答 2

2

您可以将所有错误/故障条件放在一个数组中并将其传递给$this->signup().

if ($this->form_validation->run() == FALSE) {
    $this->signup();
} 
else 
{
   $errors = array();
   if ($this->membership_model->check_field('username',$this->input->post('username'))) 
       $errors[]= "An account with the username you've entered already exists.";
   if ($this->membership_model->check_field('email_address',$this->input->post('email_address')))
       $errors[]= "An account with the e-mail you've entered already exists.";

   $this->signup($errors);
}
于 2012-04-28T23:19:25.350 回答
0

使用 && 运算符

a = 1; b = 2; if (a == 1 && b == 2) { echo "这将显示在页面上"; }

于 2012-04-28T23:15:48.643 回答