如果其中一个或两个条件都成立


If either or both condition true

如果其中一个或两个条件都返回true,我将尝试获取数组值,例如:

    $emailarr = array('arsalan@gmail.com', 'aquarious@yahoo.com', 'imran@google.com');    
foreach ($emailarr as $email) {
   if ($email !== 'aquarious@yahoo.com' || 'imran@google.com'){
    echo 'Email Send to '. $email   ;
   }   
}

我实际需要的是

if only (aquarious@yahoo.com) return true
If only (imran@google.com)    return true
if both (aquarious@yahoo.com and imran@google.com) return true

提前谢谢。

只需将您的逻辑更改为:

if ($email == 'aquarious@yahoo.com' || $email ==  'imran@google.com'){
    echo 'Email Send to '. $email   ;
}

输出:

Email Send to aquarious@yahoo.com
Email Send to imran@google.com   

您不需要"both"条件,只需要"非此即彼"。

您也可以使用if (in_array($email, array(email1, email2...)) {...}

(在foreach中,"两者"不会发生在同一迭代中。)

我不确定你想做什么,但实现你需要的一种方法是:

$emails = ['arsalan@gmail.com', 'aquarious@yahoo.com', 'imran@google.com'];
if (count($emails) == 1) {
    if (in_array('aquarious@yahoo.com', $emails)) {
        return true;
    } else if (in_array('imran@google.com', $emails)) {
        return true;
    }
} else if ((count($emails) == 2) && (in_array('aquarious@yahoo.com', $emails)) && (in_array('imran@google.com', $emails))) {
    return true;
}
return false;

此外,像在"$email_arrays"中那样将对象类型添加到变量名中不是一个好的做法$电子邮件很好。